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

5 views (last 30 days)
炫辉
炫辉 on 8 May 2024
Answered: Dyuman Joshi on 8 May 2024
最大值是两个重复的值,要得到两个的位置

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 8 May 2024
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.

More Answers (0)

Tags

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!