Matlab help with if conditional

  • Context: MATLAB 
  • Thread starter Thread starter astronut555
  • Start date Start date
  • Tags Tags
    Conditional Matlab
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 3K views
astronut555
Messages
18
Reaction score
1
Hello all,

I'm reading through some code that someone else wrote and have come across the following conditional:

if 0

figure; plot(times, average);

end;


I've never seen if used without a statement to test (ie: if x>0...) and I can't find any documentation on it anywhere.

Anyone seen this before and know what it does?

Thanks!
 
Physics news on Phys.org
Matlab's "if" command bases its decision on whether the next object is true or false, and this can be expressed also by 1 or 0. You are used to seeing an expression such as x>0, but this will evaluate to either true/1 (if the condition is true) or false/0 (otherwise). Your code might have had such a test at one time but it was replaced by 0 to force the plot command not to execute. Its possible the programmer added this plot during debug with a 1, then changed it to 0 when debug was over instead of removing the code. That way he/she can always reactivate the plot by changing one character.
 
makes sense, thanks!