Finding index of a value in the matrix

3 ビュー (過去 30 日間)
Vinay Killamsetty
Vinay Killamsetty 2020 年 4 月 12 日
コメント済み: Vinay Killamsetty 2020 年 4 月 13 日
I have a matrix "A" of size "n*2"
1st column--phase
2nd column--magnitude
I have to find the row index of a row which have particular phase (targetPhase) and maximum magnitude
I have used this code:
range=find( abs(A(:,1) - targetPhase) < 2 ); % targetPhase is the required phase
Index = set( find( max( abs(A(range,2) ) ) );
I know there is a mistake in second line
Could you please help to solve this problem with a short code

採用された回答

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020 年 4 月 12 日
This is probably the shortest you can get
range=find( abs(A(:,1) - targetPhase) < 2 ); % targetPhase is the required phase
[~,IndexMax] = max( abs(A(range,2) ) );
Index = range(IndexMax);
  1 件のコメント
Vinay Killamsetty
Vinay Killamsetty 2020 年 4 月 13 日
Thank you very much

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by