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