Relational operators == for more than 1 or 2 elements?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Emma Bromark
am 25 Apr. 2020
Kommentiert: Emma Bromark
am 26 Apr. 2020
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 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!