How do i refer to an entire row in a matrix, while only specifying one variable in that row?
Show older comments
I have a matrix consisting of 2 columns and 160 rows. My aim is to automatically generate the entire row in which the second variable is the lowest of it's column. For example:
Matrix = [1 5; 4 1; 2 7; 3 8]
I need a code which generates the second row (4 1) since 1 is the lowest number in the second column. Thank you in advance for the help!
Accepted Answer
More Answers (1)
matico
on 16 Aug 2015
Something like this:
Matrix = [1 5; 4 1; 2 7; 3 8];
SecCol = Matrix(:,2);
[val,ind] = min(SecCol);
Result = Matrix(ind,:)
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!