how to make it into for loop

1 次查看(过去 30 天)
Hello,
I am trying to make the below cose into a for loop
Would you help me with that?
file1=load('0.txt','-ascii');
a=file1(:,1);
b=file1(:,2)-r_peak1(1)/1000;
c=file1(:,3);
data=[a,b,c];
save('0.txt','data1','-ascii');
file2=load('3.txt','-ascii');
a=file2(:,1);
b=file2(:,2)-r_peak1(2)/1000;
c=file2(:,3);
data=[a,b,c];
save('3.txt','data1','-ascii');
file3=load('6.txt','-ascii');
a=file3(:,1);
b=file3(:,2)-r_peak1(3)/1000;
c=file3(:,3);
data=[a,b,c];
save('6.txt','data1','-ascii');
file4=load('9.txt','-ascii');
a=file4(:,1);
b=file4(:,2)-r_peak1(4)/1000;
c=file4(:,3);
data=[a,b,c];
save('9.txt','data1','-ascii');
Thank you

采纳的回答

Jan
Jan 2021-4-21
编辑:Jan 2021-4-21
iPeak = 0; % [EDITED]
for k = [0, 3, 6, 9]
name = sprintf('%d.txt', k);
data = load(name, '-ascii');
iPeak = iPeak + 1;
a = data(:,1);
b = data(:,2) - r_peak1(iPeak) / 1000;
c = data(:,3);
data = [a, b, c];
save(name, 'data', '-ascii');
end
  2 个评论
arthur doroshev
arthur doroshev 2021-4-21
but what about the r_peak(...)
it should also continue 1,2,3,...
arthur doroshev
arthur doroshev 2021-4-21
ok i worked it out
Thank you very much

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by