필터 지우기
필터 지우기

Global Flag

조회 수: 1 (최근 30일)
Bestun
Bestun 2012년 4월 13일
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
Richard Brown
Richard Brown 2012년 4월 14일
you can use a switch statement
switch flag
case 0
blah
case 1
blah
case 2
blah
otherwise
blah
end
Image Analyst
Image Analyst 2012년 4월 14일
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개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by