Importing xlsx files - columns of unknown length

I am currently attempting to plot 4 graphs from the results of multiple trials (an example of 4 trial file names shown below). My main issue is (I believe) that columns A and B are not the same size for all of the files. I am commonly faced with 'Subscripted assignment dimension mismatch'. I am very new to Matlab, and have had some help so far getting to the stage I am at, really need some help to quickly process some data
Any help is much appreciated.
filename = {'T1_B1_P4_R1_I2_ER1_EX3_S_3.xlsx';...
'T1_B2_P4_R1_I2_ER1_EX3_S_3.xlsx';...
'T1_B3_P4_R1_I2_ER1_EX3_S_3.xlsx';...
'T1_B4_P4_R1_I2_ER1_EX3_S_3.xlsx'};
col = {'r','g','b','k'};
figure;
hold on;
for i = 1:length(filename)
data(:,2*i-1:2*i) = xlsread(filename{i}, 2, 'A1:B400');
temp = data(:,2*i-1:2*i);
hold on
plot(data(:,2*i),data(:,2*i-1),col{i});
end

Antworten (2)

Image Analyst
Image Analyst am 6 Okt. 2014
Don't use indexes, just suck up the whole thing:
data = xlsread(filename{i}, 2, 'A1:B400');
It will resize data each time to be the size it needs to be.

6 Kommentare

Ben
Ben am 6 Okt. 2014
Although this allowed for all of my data to be plotted, it prevented the plot from being colour coded.
I really am a novice at matlab..
I have nothing to go on.....
Ben
Ben am 6 Okt. 2014
Yeah I know, I'm not having a go at all, I'm more annoyed that I can't work out what I'm doing wrong. Your help is appreciated
I meant that you didn't attach the 4 workbooks so no one can try anything. Maybe try this:
filename = {'T1_B1_P4_R1_I2_ER1_EX3_S_3.xlsx';...
'T1_B2_P4_R1_I2_ER1_EX3_S_3.xlsx';...
'T1_B3_P4_R1_I2_ER1_EX3_S_3.xlsx';...
'T1_B4_P4_R1_I2_ER1_EX3_S_3.xlsx'};
col = {'r','g','b','k'};
figure;
for i = 1:length(filename)
data = xlsread(filename{i}, 2, 'A1');
x = data(:, 2); % Extract x from column B
y = data(:, 1); % Extract y from column A
plot(x, y, col{i});
hold on;
end
Ben
Ben am 7 Okt. 2014
I just tried this, made an amendment to,
data = xlsread(filename{i}, 2, 'A1');
to data = xlsread(filename{i}, 2, 'A1:B500');
And this has plotted perfectly! Many thanks for your time! Greatly appreciated
No problem. You're welcome. If we're done here, could you go ahead and officially mark it as Accepted? Thanks.

Melden Sie sich an, um zu kommentieren.

Sean de Wolski
Sean de Wolski am 6 Okt. 2014

0 Stimmen

The problem is that you're storing this all in one array when different columns might have different sizes.
Instead, create data to be a cell array (a container) and have each excel file stored as one element in it.
data{ii} = xlsread(etc)
temp = data{ii}
plot(temp ... etc )
Now each element of data can be variably sized.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

Ben
am 6 Okt. 2014

Kommentiert:

am 7 Okt. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by