MATLAB: Global Flag

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

Best Answer

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