Prevent a for loop from overwriting

조회 수: 10 (최근 30일)
Dommal
Dommal 2016년 5월 10일
답변: Dommal 2016년 5월 10일
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
CS Researcher
CS Researcher 2016년 5월 10일
What is the error? Also, what is the size of M?

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

답변 (2개)

Walter Roberson
Walter Roberson 2016년 5월 10일
Use
Fmax{i} = max(M(:,2));
This might be empty for some files, if the files are empty.

Dommal
Dommal 2016년 5월 10일
Problem solved. There was an error in some other place in the code. Thank you for your answers.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by