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

 採用された回答

Star Strider
Star Strider 2017 年 6 月 21 日

0 投票

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

2 件のコメント

Ketan Kumar Sahu
Ketan Kumar Sahu 2017 年 6 月 21 日
Thank you so much @Star Strider for your help and marking out my mistake . my code is working now. Thanks.
Star Strider
Star Strider 2017 年 6 月 21 日
As always, my pleasure.

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2017 年 6 月 21 日

1 投票

for 2d arrays
a = [3 2 1; -5 0 6; 0 0 7];
[~,c] = max(max(a));
b = a(:,c)

カテゴリ

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by