MATLAB: How to find indices of a particular element in a matrix

index of matrix

Lets say i have a matrix A=[1 3 6;9 2 8;0 5 12] i want to find maximum of row 1,row 2 and row 3 and then findout the index of that value. Here, taking row 1 into consideration , 6 is the maximum value .So my answer should be (1,3) for row 2 it should be (2,1) .so on

Best Answer

max function returns two outputs.
[Y,I] = max(X)
I says the index of the max element.
So you can run a loop over number of rows of A, and for every row, find the maximum and its index.