MATLAB SWITCH not recognizing string from Excel spread sheet

Hi everyone,
I've been getting input from an Excel file and I want to use a SWITCH expression based on the selections. MATLAB gives the following error: SWITCH expression must be a scalar or string constant. My code looks like this:
a = excelInput;
switch a
case 'velocity'
% do something
case 'time'
% do something else
end

2 件のコメント

Stephen23
Stephen23 2015 年 7 月 30 日
編集済み: Stephen23 2015 年 7 月 30 日
The error message is telling you that the variable a is not a string or scalar numeric, which it needs to be to use with switch. So you need to look at this variable and see what class it is, or what size it is.
The switch statement itself is not the problem, the problem is what a is. So if you want help then you need to actually tell us what a is. You could use whos to do this, and tell us exactly the output.
Charles Kubeka
Charles Kubeka 2015 年 7 月 30 日
According to the whos function its a cell

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2015 年 7 月 30 日

0 投票

Try
switch a{1}

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by