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?

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2017년 8월 25일

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}

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2017년 8월 25일

답변:

2017년 8월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by