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

1 view (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 6 Dec 2014
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.

More Answers (0)

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!