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

6 Ansichten (letzte 30 Tage)
炫辉
炫辉 am 8 Mai 2024
Beantwortet: Dyuman Joshi am 8 Mai 2024
最大值是两个重复的值,要得到两个的位置

Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 8 Mai 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.

Weitere Antworten (0)

Kategorien

Mehr zu Big Data Processing finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!