how to find maximum value of a column,which satisfies a condition.
9 views (last 30 days)
Show older comments
Chandradhar Savanth
on 27 Oct 2013
Commented: Chandradhar Savanth
on 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 Comments
Accepted Answer
Azzi Abdelmalek
on 27 Oct 2013
Edited: Azzi Abdelmalek
on 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 Comments
Azzi Abdelmalek
on 27 Oct 2013
idx=M(:,4)==1;
f1=M(:,2);
max_f1=max(f1(idx))
min_f1=min(f1(idx))
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices 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!