How do I pick a minimum that is not the first value in a matrix with multiple minima?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi everyone.
I have a two column matrix M where the first column is a vertor/cell containing five elements x1, x2, x3, x4, x5 and the second column is a number. Many combinations of the x's in the first have the same correspoding number in the second column. I want to pick the minimum number in the second column with the corresponding cell in the first column that has the highest x3 and x5 out all available combinations. I used
[~, ind] = min([M{:,2}]);
P(j,:) = M(ind,:);
%Here I store the minimum and the corresponding cell in matrix P
but it picks the first minimum. I do not want just the minimum but the minimum highest x3 and x5. How do I do this?
댓글 수: 6
Walter Roberson
2014년 2월 6일
I still do not see any reason why there is always going to be a case in which both x3 and x5 are largest, no reason why it is not possible that in one case x3 is largest but x5 is not largest.
답변 (1개)
Sajid Khan
2014년 2월 6일
2 6
[4,5] 3
[1,8,7] 8
[3,5,8,7] 2
[3,5,6,9,11] 9 if M is the cell posted above. the the step
[~, ind] = min([M{:,2}]);
will return ind = 4. Which is correct in my case. But I guess you have to replace your second step by the following one
P = M(ind,1);
Because the cell elements that corresponds to minimum second column element lies in the first column, so it isn't good to search it in whole array by typing
P = M(ind,:);
If you don't want the result to be in form of a cell, then use the following syntax to convert it into a matrix
N = cell2mat(P).
If you have further questions, then you are most welcome to ask.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!