how to make it into for loop

1 view (last 30 days)
arthur doroshev
arthur doroshev on 21 Apr 2021
Edited: Jan on 21 Apr 2021
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

Accepted Answer

Jan
Jan on 21 Apr 2021
Edited: Jan on 21 Apr 2021
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 Comments
arthur doroshev
arthur doroshev on 21 Apr 2021
but what about the r_peak(...)
it should also continue 1,2,3,...
arthur doroshev
arthur doroshev on 21 Apr 2021
ok i worked it out
Thank you very much

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!