Relational operators == for more than 1 or 2 elements?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Emma Bromark
le 25 Avr 2020
Commenté : Emma Bromark
le 26 Avr 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 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Identification dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!