Switch case and matrix input
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
n = input('number of rows \n ')
for d = (1:n)
Month = {'Mar'}
Days = cell(n,1);
switch Month
case {'Jan'}
Days = Total_Days(d,1) +6;
case {'Feb'}
Days = Total_Days(d,1) - 24;
case {'Mar'}
Days = Total_Days(d,1) - 53;
case {'Apr'}
Days = Total_Days(1:end,1) - 84;
case {'May'}
Days = Total_Days(1:end,1) - 114;
case {'Jun'}
Days = Total_Days(1:end,1) - 145;
case {'Jul'}
Days = Total_Days(1:end,1) - 175;
case {'Aug'}
Days = Total_Days(1:end,1) - 206;
case {'Sep'}
Days = Total_Days(1:end,1) - 237;
case {'Oct'}
Days = Total_Days(1:end,1) - 267;
case {'Nov'}
Days = Total_Days(1:end,1) - 298;
case {'Dec'}
Days = Total_Days(1:end,1) - 328;
case {'Ja_'}
Days = Total_Days(1:end,1) - 359;
Actual_Year = Actual_Year + 1;
end
end
My code runs with an error shown like this.
SWITCH expression must be a scalar or string constant.
Error in Setting_Date_New (line 33)
switch Month
I need the answer to be in a matrix form that can compute with multiple sets of months at a time.
2 comentarios
FM
el 17 de Oct. de 2022
It sure would be helpful if the documentation specified that the switch expression must be a scalar.
Stephen23
el 17 de Oct. de 2022
"It sure would be helpful if the documentation specified that the switch expression must be a scalar."
It does. The SWITCH documentation states "An evaluated switch_expression must be a scalar or character vector. An evaluated case_expression must be a scalar, a character vector, or a cell array of scalars or character vectors."
Respuestas (1)
the cyclist
el 18 de Oct. de 2015
It's not clear to me what you are trying to do, but if you replace
Month = {'Mar'}
with
Month = 'Mar'
you will at least get past your current error.
0 comentarios
Ver también
Categorías
Más información sobre Variables 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!