how to make it into for loop

1 vue (au cours des 30 derniers jours)
arthur doroshev
arthur doroshev le 21 Avr 2021
Modifié(e) : Jan le 21 Avr 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

Réponse acceptée

Jan
Jan le 21 Avr 2021
Modifié(e) : Jan le 21 Avr 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 commentaires
arthur doroshev
arthur doroshev le 21 Avr 2021
but what about the r_peak(...)
it should also continue 1,2,3,...
arthur doroshev
arthur doroshev le 21 Avr 2021
ok i worked it out
Thank you very much

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by