Very basic error with switch

I am reading in some information from an Excel file and using it to construct and run an optimization model. I read the data
[num, txt, raw] = xlsread(openFile,xlSheet,xlRange);
Later I have
for i = 1:numActivities
switch raw(i,9)
which throws an error "SWITCH expression must be a scalar or string constant."
If I execute the code in the command window I can see
>> raw(1,9)
ans =
'Linear'
>> isscalar(raw(1,9))
ans =
1
and indeed if I loop through the entire contents of raw(:,9) and pass it to isscalar() they all come back as 1.
The column in question will always contain one of 'Linear', 'Exponential', or 'S' and tells me which function to use in constructing my objective function. Where am I going wrong here?

Answers (1)

The returned variable raw is a cell array, you can find this out by running
class(raw(1,9))
What you should use is:
switch raw{1,9}

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 25 Aug 2017

Answered:

on 25 Aug 2017

Community Treasure Hunt

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

Start Hunting!