Reputation: 266
I am working on a small project for a professor at the university who needs data sorted through MATLAB with various other operations done to the data. I have read in the data with no problem using:
filename = 'file.xlsx';
data = xlsread(filename)
With this it imports all the data into one big matrix. From here, within the file itself, there data is divided into 2 main categories, left knee and right knee.
What my issue is is I have tried to separate the data, but have not had any luck. Since the two sets are NOT divided by equal rows, I can't use a simple array to select the different columns. The green columns are set one and the gold is set two. Is there a way that I can look at the second row to see if it's left or right and then put the data into different sets that way? Or is there a better way to this?
Upvotes: 2
Views: 1056
Reputation: 680
Saw your screenshot ... you've GOT the left or right knee designation right there in the column header.
But xlsread doesn't give the column headers, only the numbers ... or does it?
From Matlab help for xlsread:
[ndata, text, alldata] = xlsread('myExample.xlsx')
ndata =
1 2 3
4 5 NaN
7 8 9
text =
'First' 'Second' 'Third'
'' '' ''
'' '' 'x'
alldata =
'First' 'Second' 'Third'
[ 1] [ 2] [ 3]
[ 4] [ 5] 'x'
[ 7] [ 8] [ 9]
xlsread returns numeric data in array ndata, text data in cell array text, and unprocessed data in cell array alldata.
So, right now you are getting "ndata" but you want to get "text" too. Set up one more additional output argument for xlsread and you should get it.
[data, text, ~] = xlsread(filename); % the ~ just means throw away that third output
Then you can use strfind or strcmp on the appropriate row to pull out "Left" or "Right."
Upvotes: 4
Reputation: 6424
If you know the data is placed in a specific range you can do this for each set of data:
filename = 'file.xlsx';
sheet = 1;
xlRange = 'B2:C3';
subsetA = xlsread(filename, sheet, xlRange)
or you can read a column of data:
columnB = xlsread(filename,'B:B')
otherwise you should separate the data after loading it into data array as you did before.
Upvotes: 0