Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

about code matlab - forgot the code! need help

Status
Not open for further replies.

Jerry_June

Member level 2
Joined
Dec 24, 2006
Messages
42
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,286
Location
Cambodia
Activity points
1,620
Forgot code!

dear all,

I want to ask all of you about code matlab, I use to created it but now m forgot. The problem, if i have to program for example if I want to solve the single equation and the system equation in the same program, mean when i am run my program it will ask me that:
*Which one you want to solve?
1- Single Equation
2- System Equation
Please choose:

when we choose it, it will loop to that place.

n one more thing after we do of each already the program will ask that:
Do you want to continue (Y/N)?:
if we type y it will loop to ask at * again, but if we type n the program will finish.

I try to do this for my other program but it not correct.


Thanks
 

Re: Forgot code!

Hi friend,

type help switch in matlab command window, you will see the follwing help. This will solve your problem:

help switch
SWITCH Switch among several cases based on expression.
The general form of the SWITCH statement is:

SWITCH switch_expr
CASE case_expr,
statement, ..., statement
CASE {case_expr1, case_expr2, case_expr3,...}
statement, ..., statement
...
OTHERWISE,
statement, ..., statement
END

The statements following the first CASE where the switch_expr matches
the case_expr are executed. When the case expression is a cell array
(as in the second case above), the case_expr matches if any of the
elements of the cell array match the switch expression. If none of
the case expressions match the switch expression then the OTHERWISE
case is executed (if it exists). Only one CASE is executed and
execution resumes with the statement after the END.

The switch_expr can be a scalar or a string. A scalar switch_expr
matches a case_expr if switch_expr==case_expr. A string
switch_expr matches a case_expr if strcmp(switch_expr,case_expr)
returns 1 (true).

Only the statements between the matching CASE and the next CASE,
OTHERWISE, or END are executed. Unlike C, the SWITCH statement
does not fall through (so BREAKs are unnecessary).

Example:

To execute a certain block of code based on what the string, METHOD,
is set to,

method = 'Bilinear';

switch lower(method)
case {'linear','bilinear'}
disp('Method is linear')
case 'cubic'
disp('Method is cubic')
case 'nearest'
disp('Method is nearest')
otherwise
disp('Unknown method.')
end

Method is linear

See also case, otherwise, if, while, for, end.

Reference page in Help browser
doc switch

enjoy
 

Re: Forgot code!

thanks in advance, oh now i found i can use if and elseif, but i want to ask you that how different between switch and if? when we use switch, and when we use if? for me i think that if easy to use then.

Added after 1 hours 41 minutes:

hmm, now for my first problem i have solve it already. I want to ask you one more question, for example if i have a*x^2+b*x+c, which are a, b, c is the input that can input from the user, after i enter the result will so, with the display like that "Do you want to continue? Y/N: " when we type Y it will start to the beginning program for input the value again, but if we type N it will finish. I try to do this but have some error, but if it work it will loop forever, don't stop.
 

Forgot code!

you can solve all your problems by using switch
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top