Manipulating Excel data in to matrices
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
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
See Also
Categories
Find more on Spreadsheets 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!