Finding the location of Maximum value in an array?

6 ビュー (過去 30 日間)
Stark Volt
Stark Volt 2022 年 2 月 18 日
コメント済み: Stark Volt 2022 年 2 月 18 日
I know that my questions is like beeing answered. I did try the same solution i find here but I dont know why it does not work below is an example.
A = [1 2 9 4 5 6 7]
[Amins, idx] = max(A)
[Amin, Aj] = max(Amins)
Ai = idx(Aj)
A =
1 2 9 4 5 6 7
**Errro Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
  1 件のコメント
Voss
Voss 2022 年 2 月 18 日
The example provided seems to work without error:
A = [1 2 9 4 5 6 7]
A = 1×7
1 2 9 4 5 6 7
[Amins, idx] = max(A) % maximum value of A is 9, at index 3
Amins = 9
idx = 3
[Amin, Aj] = max(Amins) % maximum value of Amins is 9, at idx 1
Amin = 9
Aj = 1
Ai = idx(Aj) % 1st element of idx is 3
Ai = 3

サインインしてコメントする。

採用された回答

Cris LaPierre
Cris LaPierre 2022 年 2 月 18 日
I do not follow what you are trying to do, but below is an explanation of what your code is doing.
A = [1 2 9 4 5 6 7];
% Find the maximum value (Amins) and its index (idx). Both are scalars
[Amins, idx] = max(A)
Amins = 9
idx = 3
% Find the maximum value (Amin) and its index (idx).
% Since Amins is a scalar, Amin=Amins, and Aj=1
[Amin, Aj] = max(Amins)
Amin = 9
Aj = 1
% idx is a single number. Aj is 1, so Ai = idx
Ai = idx(Aj)
Ai = 3
  2 件のコメント
Cris LaPierre
Cris LaPierre 2022 年 2 月 18 日
Perhaps you have overwritten MATLAB's max function?
Try clearing your workspace.
If that doesn't work, share the result of the following command.
which max
Stark Volt
Stark Volt 2022 年 2 月 18 日
Yes you are correct thanks for pointing out

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by