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

4 visualizaciones (últimos 30 días)
Emma Bromark
Emma Bromark el 25 de Abr. de 2020
Comentada: Emma Bromark el 26 de Abr. de 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

Respuesta aceptada

Steven Lord
Steven Lord el 25 de Abr. de 2020
Use ismember.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by