필터 지우기
필터 지우기

Find the maximum number and its location in the matrix

조회 수: 1 (최근 30일)
Kantosa
Kantosa 2013년 12월 7일
답변: Cb 2015년 4월 29일
Hi,
Right now I have this matrix K
K =
-3 -8 6 -3 -8 6 9 24 -18
-5 10 -9 -5 10 -9 15 -30 27
8 4 9 8 4 9 -24 -12 -27
-9 -24 18 12 32 -24 3 8 -6
-15 30 -27 20 -40 36 5 -10 9
24 12 27 -32 -16 -36 -8 -4 -9
9 24 -18 -15 -40 30 0 0 0
15 -30 27 -25 50 -45 0 0 0
-24 -12 -27 40 20 45 0 0 0
I wonder how I can use any method to find the maximum number and its location from this matrix.
It would be great if anyone can help me with this
Thank you very much :)

채택된 답변

Image Analyst
Image Analyst 2013년 12월 7일
Really really easy, and pretty much the same algorithm any any programming language, like others that you may know. Hint:
[rows, columns] = size(K)
maxValue = -inf;
rowAtMax = 0;
colAtMax = 0;
for column = 1 : columns
for row = 1 : rows
if K(........
end
end
There, it's practically all done for you.

추가 답변 (2개)

Andrei Bobrov
Andrei Bobrov 2013년 12월 7일
편집: Andrei Bobrov 2013년 12월 7일
[val,idx] = max(K(:));
[ir,ic] = ind2sub(size(K),idx);

Cb
Cb 2015년 4월 29일
Im after a similar function in a project I'm working on but i can't seem to get this to work..

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by