let's say , I have matrix
A=[3 1;4 9 ;5 7 ];
A=[3 1
4 9
5 7 ];
I can find the maximum value from matrix A is 9:
max_value=max(max(A));
How can I get the value is in same row of 9, that is, 4 ?

 採用された回答

madhan ravi
madhan ravi 2019 年 8 月 16 日

1 投票

[Val,ix]=max(A(:));
[r,~]=ind2sub(size(A),ix);
A(r,:) %complete row where maximum exists

5 件のコメント

ha ha
ha ha 2019 年 8 月 16 日
You are right. But, How can I get value "4"?
madhan ravi
madhan ravi 2019 年 8 月 16 日
A(r,1)
ha ha
ha ha 2019 年 8 月 16 日
編集済み: ha ha 2019 年 8 月 16 日
you assumed that , the value "4" is in the 1st column of matrix A. But, actually, I don't know where it is (It may be in 1st or 2nd column of matrix A)
Thanks so much madhan ravi
I edit form your answer
Stephen23
Stephen23 2019 年 8 月 16 日
>> A = [3,1;4,9;5,7]
A =
3 1
4 9
5 7
>> [V,X] = max(A(:));
>> [R,C] = ind2sub(size(A),X);
>> A(R,3-C)
ans = 4
madhan ravi
madhan ravi 2019 年 8 月 16 日
[Val,ix]=max(A(:));
[r,c]=ind2sub(size(A),ix);
Wanted = A(r,setdiff(1:size(A,2),c))

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

その他の回答 (2 件)

KSSV
KSSV 2019 年 8 月 16 日

0 投票

[val,idx] = max(A(:)) ;
A(idx,:)

1 件のコメント

ha ha
ha ha 2019 年 8 月 16 日
編集済み: ha ha 2019 年 8 月 16 日
Your answer is wrong. Plz check it again

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

ha ha
ha ha 2019 年 8 月 16 日

0 投票

[Val,ix]=max(A(:));
[r,c]=ind2sub(size(A),ix);
A(r,setdiff(1:size(A,2),c),:);

2 件のコメント

madhan ravi
madhan ravi 2019 年 8 月 16 日
What’s the hurry before editing the comment?? XD . I was using my mobile to answer and I just mistyped the colon inside setdiff().
ha ha
ha ha 2019 年 8 月 16 日
編集済み: ha ha 2019 年 8 月 16 日
Sorry madhan ravi.
Thank so much for your prompt reply
Hope all bests to you.

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

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

タグ

タグが未入力です。

質問済み:

2019 年 8 月 16 日

編集済み:

2019 年 8 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by