Excel sheet extraction data
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I have 20 excel sheet which contain a bunch of data. I want to extract element from these excel and make 2 matrix.
the first matrix is : row 32 from each excel sheet and only three elemet in coloum 6,8 and 12
the second matrix is row 33 from each excel sheet and only three element which are again element 6,8 and 12.
Is there an easy way to do it instead of importing each excel ark then hand piciking the elemet of each 20 excel ark and making them into a matrix ?
댓글 수: 0
답변 (2개)
Dave B
2021년 11월 16일
편집: Dave B
2021년 11월 16일
When you call readtable (or readmatrix or readcell) you can specify a range. I think the range has to be contiguous (i.e. you could grab row 32 columns 6 to 12.
Having said that, it's probably easier to just read in the whole row. That's still less than reading in the whole thing (though you can check performance, my guess is it makes little difference):
a=readmatrix('foo.xlsx','Sheet','Sheet1','Range','F32:L32');
a([1 3 7])
% probably easier to read the whole row in:
b=readmatrix('foo.xlsx','Sheet','Sheet1','Range','32:32');
b([6 8 12])
% readtable version
c=readtable('foo.xlsx','Sheet','Sheet2','Range','33:33');
c(:,[6 8 12])
댓글 수: 7
Dave B
2021년 11월 19일
For different files it's similar:
fp = 'C:\mypath\to\myexcelfiles';
% this is all files in a folder...if you have a different subset,
% or they're in different places, you'll need to come up with an
% alternate approach to telling MATLAB which files to read...
fl = dir(fullfile(fp,'*.xlsx'));
for i = 1:numel(fl)
a = readmatrix(fullfile(fp,fl(i).name), 'Range', 'F32:L33')
end
Image Analyst
2021년 11월 16일
No "easier" way. Since you have 20 different workbooks with unique filenames, you're going to have to import each one one-at-a-time, and then extract the data and paste it into your two output matrices. See the FAQ for code samples to process a sequency of files.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!