Hi community,
I noticed a problem with the following code:
year = '2001'if year == '2000' a = 1elseif year == '2006' | year == '2007' | year == '2008' | year == '2009' | year == '2010' | year == '2011' | year == '2014' | year == '2015' a = 2end
Somehow this code gives out a = 2, which obviously is not wanted, as the conditions of the elseif line are not met.
If I just set one of the years as the elseif-condition without "|", the code does not give out a = 2, which is fine.
I know that I can use double numbers instead of strings, which works correctly.
So I don't need a solution, but an explanation, why this occurs…
Can you reproduce this false outcome?
Has matlab a general problem with strings in if conditions?
Or do I have an understanding problem how if-elseif works?
Best Answer