Finding number in a column of a matrix and retrieving corresponding number from adjacent column
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Satej
am 6 Dez. 2014
Kommentiert: Star Strider
am 6 Dez. 2014
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
0 Kommentare
Akzeptierte Antwort
Star Strider
am 6 Dez. 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.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!