How do I pick a minimum that is not the first value in a matrix with multiple minima?
1 view (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 6 Feb 2014
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.
Answers (1)
Sajid Khan
on 6 Feb 2014
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.
See Also
Categories
Find more on Logical 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!