MATLAB: Relational operators == for more than 1 or 2 elements

MATLABrelational

I'm trying to make a vector containg values for every day of the year. I'm trying to set the number of days for each month based on the following kind of loop. Matlab dont seem able to understand multiple arguments like this, it simply sets n = 31 for all cases. Brackets or not/ dubble or simle | dont seem to matter. Does anyone know how to solve this? I suppose an ugly way would be to simple write 12 seperate statement eg. if i == 1; n= 31 elseif i == 2; n= 28, elseif i == 3; n=31 etc.
for i = 1:12
if i == (1 | 3 | 5 | 8 | 10 | 12)
n = 31;
% elseif i == 4 || 6 || 7 || 9 || 11
elseif i == (4 | 6 | 7 | 9 | 11)
n = 30;
else
n = 28;
end

Best Answer

  • Use ismember.