Relational operators == for more than 1 or 2 elements?

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

 채택된 답변

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품

태그

질문:

2020년 4월 25일

댓글:

2020년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by