필터 지우기
필터 지우기

import multiple spreadsheats at once (.xlsx files)

조회 수: 1 (최근 30일)
Joey Smit
Joey Smit 2017년 5월 12일
댓글: Joey Smit 2017년 5월 13일
so I have to import multiple spreadsheats at once (roughly 400). I can import them all manually like
filename='20150901_1.xlsx'
A1=xlsread(filename);
filename2='20150902_1.xlsx'
A2=xlsread(filename2)
Is there a faster way to do this? The spreadsheats are all 2D matrices. thanks in advance

답변 (1개)

Joseph Cheng
Joseph Cheng 2017년 5월 13일
편집: Joseph Cheng 2017년 5월 13일
well first you'll want to get away from generating variables in that fashion as you'll basically have A400 or more which is hard to keep track of. instead of manually you can use the function dir() which can poll a file for the files in a folder. (in combination with uigetdir/uigetfile you can navigate to another folder without coding in the file locations.)
example:
xlfiles = dir('*.xlsx')
for ind = 1:numel(xlfiles)
A(:,:,ind) = xlsread(xlfiles(ind).name);
end
if they are at different sizes you can use structs which i think goes like this:
data = struct('A',[])
for ind = 1:numel(xlfiles)
data(ind).A = xlsread(xlfiles(ind).name);
end
or alternatively put it into a cell array
  댓글 수: 1
Joey Smit
Joey Smit 2017년 5월 13일
Ok, I get the idea but what does the .name thing do in the 3rd line? I can't find any example of it. I've been able to import some of the xlsx files manually using the same line of code (more or less), but I could skip the .name stuff there.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by