Manipulating Excel data in to matrices

3 views (last 30 days)
gooniyath
gooniyath on 27 Sep 2016
Commented: gooniyath on 27 Sep 2016
Hi,
I have an excel file with 50 sheets. Each sheet has about 280000 values(700x400). I need to write a MATLAB script to to break up the excel file based on excel cells. For example, I want it to select all values for excel cell A1, from all 50 sheets and place them into a matrix, all values for excel cell A2, from all 50 sheets and place them into a another matrix and so on. I have written some code that does it but its no very efficient in that I would need to write it for each excel cell to complete the task, which would be about 280000 times.
[type,sheetname] = xlsfinfo('test.xlsx');
m = size(sheetname,2);
alldata = cell(1, m);
M = zeros(1,100);
for i=1:1:m;
Sheet = char(sheetname(1,i)) ;
xlRange = 'C3';
num{i} = xlsread(filename,Sheet,xlRange);
alldata = num;
M = max(alldata{1,i});
end
Any help to make my code more efficient or advice on how to go about it be really helpful as I am pretty new to using MATLAB.
Thanks, Akshay

Answers (1)

Walter Roberson
Walter Roberson on 27 Sep 2016
700*400*50 will fit entirely into memory, so read all of the values at one time and then do whatever you need to do for writing.
[type,sheetname] = xlsfinfo('test.xlsx');
m = size(sheetname,2);
alldata = cell(1, m);
for i=1:1:m;
Sheet = char(sheetname(1,i)) ;
num{i} = xlsread(filename,Sheet,xlRange);
end
Now you can process the cell array num .
num_mat = cat(3, num{i});
Now num_mat will be a 700 x 400 x m numeric array (provided the same amount was written on each sheet). You can loop,
for row = 1 : 700
for col = 1 : 400
thisdata = reshape( num_mat(row, col, :), [], 1);
... and now it is a vector containing data for the 50 sheets, that you could write out
end
end
  1 Comment
gooniyath
gooniyath on 27 Sep 2016
Thanks for the help. For num_mat it just gives me a single 700 x 400 matrix rather than a 700 x 400 x m

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!