필터 지우기
필터 지우기

如何得到361x91数组中重复最大值的位置

조회 수: 2 (최근 30일)
炫辉
炫辉 2024년 5월 8일
답변: Dyuman Joshi 2024년 5월 8일
最大值是两个重复的值,要得到两个的位置

채택된 답변

Dyuman Joshi
Dyuman Joshi 2024년 5월 8일
Use find -
%Sample data
mat = magic(4);
mat = [mat; 1 4 9 16]
mat = 5x4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 1 4 9 16
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
%Get the maximum value
val = max(mat, [], 'all')
val = 16
%% Find the indices of all occurences of the max value
%Linear indices
idx = find(mat==val)
idx = 2x1
1 20
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
%Subscript indices
[r,c] = find(mat==val)
r = 2x1
1 5
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
c = 2x1
1 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Note - Use tolerance to compare for floating point values.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!