Global Flag

Dear All I am using global flag in my code, and there is two parts of equations to be run. e.g when flag =0 , there is set of equations (let's call it No.1 )should be run, while when flag = 1, other set of equations (set No.2)should be run.However, when I am running the code with using flag =0 or = 1, for both case only set No.2 (of equations) is running. Any suggestion please ?
Regards

 采纳的回答

Image Analyst
Image Analyst 2012-4-13
Are you sure you're using == and not =?
if flag = 1 % Incorrect.
if flag == 1 % Correct.
Or better yet, if there are only those two values, make flag a logical
if flag
or
if ~flag

3 个评论

Bestun
Bestun 2012-4-13
Dear
Thanks for reply
Sorry there was a typo in my previous message . I meant flag == 1
I have another value of flag which is running a test for my equations (flag==2).
could I use (in this case for there values of Flag), (~flag) command?
you can use a switch statement
switch flag
case 0
blah
case 1
blah
case 2
blah
otherwise
blah
end
So is it solved or not? If you're checking each value of flag (1,2,3,etc) with an if statement and they're integers and you're using double equals, then there is no reason it should always go into the same if block regardless of what the value of flag is.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by