Set a variable equal to the string of the corresponding season.
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
I am trying to write a code that kicks out the corresponding season when a certain month is randomly generated.
For this I need to create a variable named season equal to the string corresponding season (spring, summer, fall, winter)
I have the following:
BD = randi(12)
if BD >2 & BD <6
    season = Spring
elseif BD >5 & BD <9
    season = Summer
elseif BD >8 & BD <12
    season = Fall
else BD >11 & BD <3
    season=Winter
end
1 comentario
Respuestas (2)
  Walter Roberson
      
      
 el 14 de Abr. de 2023
        seasons = categorical({'Spring', 'Summer', 'Fall', 'Winter'});
Spring = seasons(1); Summer = seasons(2); Fall = seasons(3); Winter = seasons(4);
BD = randi(12)
if BD >2 & BD <6
    season = Spring
elseif BD >5 & BD <9
    season = Summer
elseif BD >8 & BD <12
    season = Fall
else BD >11 & BD <3
    season=Winter 
end
0 comentarios
  Steven Lord
    
      
 el 14 de Abr. de 2023
        BD = (1:12).';
whichMonth = discretize(BD, ...
    [1 3 6 9 12 12], ...
    'categorical', ...
    ["Winter", "Spring", "Summer", "Fall", "Winter"]);
results = table(BD, whichMonth)
For values of BD in the range [1, 3) the value of whichMonth is the categorical value "Winter".
For values of BD in the range [3, 6) the value of whichMonth is the categorical value "Spring".
etc.
The last bin is handled differently as it includes both its left and right edge. The previous bins only included their left edges.
For values of BD in the range [12, 12] the value of whichMonth is the categorical value "Winter".
0 comentarios
Ver también
Categorías
				Más información sobre Environmental Engineering en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



