Retrieve loop counter values in nested loop, and plotting specific calculation
Afficher commentaires plus anciens
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 commentaires
dpb
le 14 Août 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
le 15 Août 2018
Modifié(e) : Pit Probst
le 15 Août 2018
Adam Danz
le 15 Août 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
le 15 Août 2018
Modifié(e) : Pit Probst
le 15 Août 2018
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Exponents and Logarithms dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!