load multiple .mat file and do same calculation on each file

조회 수: 1 (최근 30일)
MM Asim
MM Asim 2017년 5월 6일
답변: Navdeep Goel 2019년 9월 29일
i have 100 .mat file name "A00001-A00100". i want to create loop that do calculation (written in code) one by one on each file but my code just do calculation on first file (A00001.mat) only. please help!,
% loop to do same calculation on each file,
for i=1:100
load(['A000' num2str(i,'%02d') '.mat' ]);
%calculations
N=9000;
gqrs('A00001',N);
ann=rdann('A00001','qrs',[],N);
[tm,sig]=rdsamp('A00001',[],N);
end

채택된 답변

mizuki
mizuki 2017년 5월 6일
Your code works only for A00001 because you set 'A00001' as input arguments for GQRS, RDANN, RDSAMP. Change the numbers with index i.
for i=1:5
str = 'A000' num2str(i,'%02d');
filename = [str, '.mat']
load(str);
% calculations
N = 9000;
gqrs(str, N);
ann = rdann(str, 'qrs', [], N);
[tm,sig] = rdsamp(str, [], N);
end
Also, if you breakdown the problem, you can easily find which part you need to change.
  1. Made the maximum loop index smaller from 100 to 5.
  2. To check the mat-file was loaded correctly, created the variable, filename.
  3. Since the first loading part worked correctly, checked the second part.
  댓글 수: 1
MM Asim
MM Asim 2017년 5월 8일
Yes it work, code that you have provide work absolutely great after little modification in second line and also your recommendations to solve the problem are helpful for me.
str = ['A000' num2str(i,'%02d')]; % 2rd line with some change.
thanks a lot Mr. Mizuki

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

추가 답변 (1개)

Navdeep Goel
Navdeep Goel 2019년 9월 29일
for i=1:5
str = 'A000' num2str(i,'%02d');
filename = [str, '.mat']
load(str);
% calculations
N = 9000;
gqrs(str, N);
ann = rdann(str, 'qrs', [], N);
[tm,sig] = rdsamp(str, [], N);
end
In the above code, load(str) should be load(filename)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by