Finding number in a column of a matrix and retrieving corresponding number from adjacent column

1 次查看(过去 30 天)
Hi I am having issues with indexing from matrix. Can you please advise on the question below? e.g. I have a matrix CV = [1 11; 3 13; 4 14; 5 17; 8 6]; I want to find the max value in column 1 (which in this case is 8) and get the corresponding value in the adjacent column (which is 6 in this case).
Thanks SATEJ

采纳的回答

Star Strider
Star Strider 2014-12-6
Ask max for its second output, the index of the maximum value. (This works for min as well.)
Example:
CV = [1 11; 3 13; 4 14; 5 17; 8 6];
[CVmax,idx] = max(CV(:,1), [], 1);
result = [CVmax, CV(idx,2)]
produces:
result =
8 6
as desired.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by