Manipulating Excel data in to matrices

조회 수: 2 (최근 30일)
gooniyath
gooniyath 2016년 9월 27일
댓글: gooniyath 2016년 9월 27일
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

답변 (1개)

Walter Roberson
Walter Roberson 2016년 9월 27일
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
gooniyath
gooniyath 2016년 9월 27일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by