Prevent a for loop from overwriting
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi everyone,
I have a for loop and 90 iterations. After running it I want to have a vector Fmax with 90 entries, one entry per each iteration. So far I am getting the 1x1 vector with the result from the last iteration. My code:
for i = 1:90 % number of tests done
File1 = strcat(Dir,num2str(i),'_s',cellSamples(i),'_',cellScrews(i),'_',cellThickness(i),'.txt');
File1=char(File1);
M = dlmread(File1,'\t',2,0)
Fmax=max(M(:,2))
end
I tried with
Fmax(i)=max(M(:,2))
but it returns an error.
Thank you for any suggestions.
1 Kommentar
Antworten (2)
Walter Roberson
am 10 Mai 2016
Use
Fmax{i} = max(M(:,2));
This might be empty for some files, if the files are empty.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!