Retrieve loop counter values in nested loop, and plotting specific calculation
Ältere Kommentare anzeigen
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 Kommentare
dpb
am 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
am 15 Aug. 2018
Bearbeitet: Pit Probst
am 15 Aug. 2018
Adam Danz
am 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
am 15 Aug. 2018
Bearbeitet: Pit Probst
am 15 Aug. 2018
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Exponents and Logarithms finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!