Finding the highest mountain peak
조회 수: 6 (최근 30일)
이전 댓글 표시
How might i find the highest mountain peak, and its name, from a defined set of named mountains?
I have data for a set of 10 mountains as 4 matrices.
[X] and [Y] are single row and column matrices defining distances along orthogonal horizontal coordinates.
[Z] is a 3D matrix (:,:,i) containing corresponding x,y height values and an index i=1:10 to define the mountain set.
[Name] is a 10 element 1D text matrix of of the mountain names.
Using a for loop I can plot the surfaces, find the peaks of each mountain and their names:
surf(X,Y,Z(:,:,i))
maximum=max(max(Z(:,:,i)))
Name(i)
How might i find the overall highest peak, and its name in one hit (without the loop)?
댓글 수: 0
채택된 답변
Image Analyst
2022년 9월 29일
Why can't you just do this to find the row and column of the max for each of the 10 slices of data:
for k = 1 : size(Z, 3)
% Extract this mountain set.
thisMountainSet = Z(:, :, k);
% Find the max value of it
maxValue(k) = max(thisMountainSet(:));
% Find row(s) and column(s) where it occurs.
[rowsOfMax, colsOfMax] = find(thisMountainSet == maxValue(k));
% Now do something with this information....
end
댓글 수: 3
Image Analyst
2022년 9월 30일
Personally I prefer using find() to get the rows and columns directly and immediately rather than using the confusing, intermediate function ind2sub(). Note also about the solution you accepted, max only gives you one max location (if you ask for the index), not all of them like find() does, so it your max occurs in more than one location, you may want to know that, and max won't tell you that.
추가 답변 (2개)
커뮤니티
더 많은 답변 보기: ThingSpeak 커뮤니티
참고 항목
카테고리
Help Center 및 File Exchange에서 Pulsed Waveforms에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!