Retrieve loop counter values in nested loop, and plotting specific calculation
이전 댓글 표시
Hello all. My questions are as commentated
count = 0 ;
vec = zeros([],7) ;
for a=1:3
A= 2*a ;
for b=a+1:6
B=3*b ;
for c=b+1:10
C=4*c ;
count = count+1 ;
total=sum([A B C])
vec(count,:)=[a b c A B C total];
end
end
end
value = max(total) % get max and return values of a,b,c when this happens
% plotting corresponding individual calculation A B C for the max(total)
end
댓글 수: 4
dpb
2018년 8월 14일
[vmax imax] = max(vec(:,end)) % get max and return values of a,b,c when this happens
vec(imax,:) contains the desired quantities.
Not sure what you want to do regarding a plot for a single point?
Pit Probst
2018년 8월 15일
편집: Pit Probst
2018년 8월 15일
Adam Danz
2018년 8월 15일
I don't follow your explanation. However, when I run your code I get an error on the first iteration since
[a b c A B C total]
has 10 elements but
vec(count,:)
expects 11 elements. On the 2nd iteration there are 11 elements in [a b c...] so there isn't an error.
Pit Probst
2018년 8월 15일
편집: Pit Probst
2018년 8월 15일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Exponents and Logarithms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!