how to find maximum value of a column,which satisfies a condition.
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Chandradhar Savanth
le 27 Oct 2013
Commenté : Chandradhar Savanth
le 27 Oct 2013
hi.. suppose i have a matrix as given below
x f1 f2 rank
0.0002 0.0000 3.9991 1.0000
0.7672 0.5886 1.5198 1.0000
1.0987 1.2071 0.8124 1.0000
1.1767 1.3845 0.6779 1.0000
2.4407 5.9572 0.1943 1.0000
-0.2008 0.0403 4.8434 2.0000
3.0549 9.3324 1.1128 2.0000
3.5944 12.9199 2.5422 3.0000
4.0472 16.3800 4.1911 4.0000
-4.6946 22.0392 44.8175 5.0000
here x,f1,f2,rank represents 1st,2nd,3rd,4th columns respectively of the above matrix.
i want to find maximum value and minimum value of 'f1' column whose 'rank'=1 i.e, my answer should be max.value=5.9572,min.value = 0.0000
similarly max.value and min.value of 'f2' column whose 'rank'=1;i.e, my answer should be
max.value = 3.9991;min.value= 0.1943
is there a method to find out without using loops .
Thank you
with regards,
Chandradhar Savanth.
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 27 Oct 2013
Modifié(e) : Azzi Abdelmalek
le 27 Oct 2013
You can use max and min function. If M is your matrix
f1=M(:,2);
max_f1=max(f1)
min_f1=min(f1)
% you can do the same for f2
f2=M(:,3);
3 commentaires
Azzi Abdelmalek
le 27 Oct 2013
idx=M(:,4)==1;
f1=M(:,2);
max_f1=max(f1(idx))
min_f1=min(f1(idx))
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!