필터 지우기
필터 지우기

How to use a batch mode to import files?

조회 수: 7 (최근 30일)
Chaitanya Bade
Chaitanya Bade 2017년 4월 6일
댓글: Chaitanya Bade 2017년 4월 6일
Hi, I have 3 files named 1.xlsx, 2.xlsx, 3.xlsx in a folder. Now, I want to run all the three files at a time using a batch mode. I have written a for loop code but I does not work. It brings out the first result, but it is failing to process all the three files. However, it does not show any error.It just shows the results of the first file and stops.
files = dir('C:\Users\Deakin Uni\Documents\MATLAB\a\*1*');
fNames = {files.name};
%for each file
for k= 1: length(fNames)
% extract file name
fName = ['C:\Users\Deakin Uni\Documents\MATLAB\a\', fNames{k}];
[XDATA, TIMESTEPS] = importfile(fName);
a1 = XDATA - mean (XDATA);
plot(TIMESTEPS, a1);
[peakvals,peaklocs] = findpeaks(a1, 'minpeakdistance',50, 'minpeakheight', 0.00001);
peaktime = TIMESTEPS(peaklocs);
createfigure4(TIMESTEPS, a1, peaktime, peakvals)
saveas(gcf, 'chaitu.fig')
end
Thanks in advance!!
  댓글 수: 3
Chaitanya Bade
Chaitanya Bade 2017년 4월 6일
편집: Chaitanya Bade 2017년 4월 6일
As in? There are 3 files in the folder with the names 1.xlsx, 2.xlsx, 3.xlsx
Chaitanya Bade
Chaitanya Bade 2017년 4월 6일
Mate, i got you. I found the solution. Thanks!

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

채택된 답변

JohnGalt
JohnGalt 2017년 4월 6일
From this: files = dir('C:\Users\Deakin Uni\Documents\MATLAB\a\*1*');
it looks like you're only loading the first one... shouldn't it be:
files = dir('C:\Users\Deakin Uni\Documents\MATLAB\a\*.xlsx');
  댓글 수: 4
JohnGalt
JohnGalt 2017년 4월 6일
you got the separate graphs sorted?
Chaitanya Bade
Chaitanya Bade 2017년 4월 6일
Yes. I used the following code saveas(gcf,sprintf('chaitu%d.fig',k));

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by