Switch case and matrix input
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
FM
am 17 Okt. 2022
It sure would be helpful if the documentation specified that the switch expression must be a scalar.
Stephen23
am 17 Okt. 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."
Antworten (1)
the cyclist
am 18 Okt. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Variables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!