how to find maximum value of a column,which satisfies a condition.
조회 수: 8 (최근 30일)
이전 댓글 표시
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
채택된 답변
Azzi Abdelmalek
2013년 10월 27일
편집: Azzi Abdelmalek
2013년 10월 27일
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
Azzi Abdelmalek
2013년 10월 27일
idx=M(:,4)==1;
f1=M(:,2);
max_f1=max(f1(idx))
min_f1=min(f1(idx))
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!