string input for xlsread of a sheet

5 views (last 30 days)
Travis
Travis on 6 Jun 2014
Answered: Sara on 6 Jun 2014
I am trying to get the program to read the sheet names, filter the sheet names in the excel file and place all that fit the category in it's own array and then use that array as inputs for the sheet name in a for loop. I'm getting the following error:
Error using xlsread (line 139) Sheet argument must be a string or an integer.
%Data Read Test%
file = 'file.xlsx';
[status,sheets] = xlsfinfo(file);
%Data Classification%
sheetmatch = strmatch('DLC',sheets);
cases = sheets(:,sheetmatch);
n = size(cases,2);
for i=1:n
s = cases(i);
new_s = strrep(s,'_','-');
%time read%
t = xlsread(file,s,'E7:E12006')
%sampling frequency%
fs = 1/(t(2,:)-t(1,:));
%pitching moment reads%
b1 = xlsread(file,s,'F7:F12006')
b2 = xlsread(file,s,'G7:G12006')
b3 = xlsread(file,s,'H7:H12006')
end;
so what it's telling me is that it's not seeing the variable s as a string. Is there a way to get it so that the variable s (which changes with each step of i) to be input as the string for the sheet name which i'm trying to call?
Current cases matrix: The current cases matrix is as follows:
Columns 1 through 3
'DLC_1' 'DLC_2' 'DLC_3'
Columns 4 through 6
'DLC_4' 'DLC_5' 'DLC1_6'
Column 7
'DLC_7'
Thanks, Travis

Accepted Answer

Sara
Sara on 6 Jun 2014
cases is a cell array, use:
cases{i}

More Answers (0)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!