How do i find the location by using max and find function?

조회 수: 6 (최근 30일)
Samantha Pham
Samantha Pham 2020년 9월 15일
댓글: Samantha Pham 2020년 9월 15일
I have a Matrix
K = [Mon Tue Wed Thu Fri Sat Sun]
L = [1 9 6 5 4 7 3 ;
3 5 6 4 1 8 2]
M = [K; L]
Finding the location that contain the maximum value. For example: 9 is the maximum value in this case and the column that contains it is Tue. So, how do we indicate the name of the column contain the maximum value?
Thank you!

채택된 답변

Image Analyst
Image Analyst 2020년 9월 15일
Don't use max() - it only gives the location of the first global max, not all of them (in the case the max occurs in more than one location). Try this
maxValue = max(yourMatrix);
[rows, columns] = find(yourMatrix == maxValue)
Where yourMatrix is L or Ice or whatever you want.
If you want local maxima, use imregionalmax().
  댓글 수: 2
Samantha Pham
Samantha Pham 2020년 9월 15일
It works! but one small problem, how do i transfer those number into given name.
i have third column and tenth row, the value will be day 25 and location WSW324.
Thank you very much!!!
Samantha Pham
Samantha Pham 2020년 9월 15일
Nvm, I figure it out. Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

madhan ravi
madhan ravi 2020년 9월 15일
doc max % second output , does what you need
  댓글 수: 3
madhan ravi
madhan ravi 2020년 9월 15일
“How do i correct this?”
If it were me I would provide a valid example so that the person answering the question won’t have any trouble. Did you paste the K in command window and see what MATLAB has to say?
Samantha Pham
Samantha Pham 2020년 9월 15일
So this is the actual problem i want to ask, i was provided with these three table. My task is to find the maximum value in the Ice table, after that indicate where the maximum number attaches with which location and that number was recorded on what day. The last four sentences are the result of how it should be.
This is what i have so far...
Thank you for being patient!
[r,~] = size(Ice);
[~,c] = size(Ice);
TotalMM = r.*c;
OAveMM = mean(Ice,"all");
OMaxMM = max(Ice(:));

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by