0
votes

I'd like to be able to create a column vector whose values in each row correspond to the column in a matrix with the max value in that specific row.

For example, If I have a matrix such as:

A = [1,5,2;3,1,1;0,1,0];

I'd end up with the matrix:

maxValueColumns = transpose([2,1,2]);

Is there an easy/efficient way to do this?

1

1 Answers

1
votes

You're looking for max():

A = [1,5,2;3,1,1;0,1,0];
[~, maxValueColumns] = max(A, [], 2); % 'maxValueColumns' will contain [2; 1; 2]