필터 지우기
필터 지우기

How to load the data from a specific excel files in a loop?

조회 수: 2 (최근 30일)
R7 DR
R7 DR 2015년 2월 20일
편집: Sad Grad Student 2015년 2월 20일
Hi
I have the data files, and I have to load the data into matlab when ever the condition matches.
The condition should be depended on my file name.
for example the data files are ''1.xlsx 2.xlsx 5.xlsx 8.xlsx''
for i=1:10 if i= the file name, then I have to load the dat in to excel.
my file names are changing frequently, so with out modifying the program I just want to put a condition and load the data.
how to write a condition in this case ?
Thanks.

채택된 답변

Sad Grad Student
Sad Grad Student 2015년 2월 20일
편집: Sad Grad Student 2015년 2월 20일
Try this and let me know if it works!
% cd (<directory containing all the files you want to load>)
allfiles = dir;
allfiles(1:2) = []; %this is because allfiles(1) = . & allfiles(2) = ..
for i = 1:10
if allfiles(i).name == strcat(sprintf('%d',i),'.xlsx')
fname = allfiles(i).name; %or = strcat(sprintf('%d',i),'.xlsx');
f = xlsread(fname);
end
end

추가 답변 (0개)

카테고리

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