MATLAB: How to find row values

rowvalues

Hello everyone, I have a matrix a = [3 2 1; -5 0 6; 0 0 7], where I know the maximum value in the matrix is 7. I want to know the respective row values of the 7, i.e 1,6 and the new matrix b =[1 6 7](the row of the maximum value 7).Please help me with code.
I appreciate your help, TIA, Ketan

Best Answer

You are confusing rows and columns. The result you want for ‘b’ is column 3, not row 3:
a = [3 2 1; -5 0 6; 0 0 7];
ix = find(a(:) == max(a(:))); % Find Index Of Maximum
[~,c] = ind2sub(size(a),ix); % Determine Column Of Maximum
b = a(:,c)
b =
1
6
7