Switch case and matrix input
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
FM
il 17 Ott 2022
It sure would be helpful if the documentation specified that the switch expression must be a scalar.
Stephen23
il 17 Ott 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."
Risposte (1)
the cyclist
il 18 Ott 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 Commenti
Vedere anche
Categorie
Scopri di più su Variables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!