Reputation: 41
I have this matrix
v=[4,-2,1;-2,1,-1;-2,3,6]
How can i return the max value of specific col with its row index ? Knowing that i used this function :
[amax,rowIdx]=max(abs(v(k:n,k)),[],1)
but it doesn't work well
here is my code :
v=[4,-2,1;-2,1,-1;-2,3,6] n=3; for k=1:n-1 [amax,rowIdx]=max(abs(v(k:n,k)),[],1) end
Upvotes: 0
Views: 28
Reputation: 540
If I understand your question correctly, you want to get maximum of third column?
[max_val, max_idx] = max(v(:, 3));
you select the third column from the matrix -> that gives you a single vector. max then operates on this vector and returns the max value together with its position, which is the row index in the original matrix.
Upvotes: 1