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

5 次查看(过去 30 天)
炫辉
炫辉 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 中查找有关 Big Data Processing 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!