Retrieve loop counter values in nested loop, and plotting specific calculation
Show older comments
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 Comments
dpb
on 14 Aug 2018
[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
on 15 Aug 2018
Edited: Pit Probst
on 15 Aug 2018
Adam Danz
on 15 Aug 2018
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
on 15 Aug 2018
Edited: Pit Probst
on 15 Aug 2018
Accepted Answer
More Answers (0)
Categories
Find more on Exponents and Logarithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!