Find Minimum based on new criteria

3 ビュー (過去 30 日間)
mr mo
mr mo 2017 年 11 月 5 日
コメント済み: Star Strider 2017 年 11 月 5 日
Hi. Suppose I have a matrix A e.g.
A=[
8.2505 4.8825 2.2563 0.0020 0
8.2505 4.8825 2.2687 0.0020 1
8.2505 4.8825 2.2813 0.0020 1
8.2505 4.9325 2.2813 0.0020 0
8.2505 4.9325 2.2938 0.0020 1
8.2755 4.7575 2.2437 0.0020 0
8.2755 4.7575 2.2563 0.0020 0
8.2755 4.7575 2.2687 0.0020 1
8.2755 4.8075 2.2188 0.0020 0
8.2755 4.8075 2.2313 0.0020 0
8.2755 4.8075 2.2437 0.0020 1
8.2755 4.8075 2.2563 0.0010 1
8.2755 4.8075 2.2687 0.0010 1];
I want to find the row that its value in third column is minimum and the value in fifth column is 1; if the value in fifth column is 0, then I want to find the row that has the next minimum value in third column and its value in fifth column is 1. Thanks for your help.

採用された回答

Star Strider
Star Strider 2017 年 11 月 5 日
This works:
row = (A(:,3) == min(A(A(:,5)==1,3))) & (A(:,5) == 1); % Row Index (Logical Vector)
Result = A(row,:) % Desired Row
If you want the number index of the row, use the find function:
row_index = find(row);
  2 件のコメント
mr mo
mr mo 2017 年 11 月 5 日
Thank you very much.
Star Strider
Star Strider 2017 年 11 月 5 日
As always, my pleasure.

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

その他の回答 (1 件)

Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan 2017 年 11 月 5 日
編集済み: Kaushik Lakshminarasimhan 2017 年 11 月 5 日
minval = min(A(A(:,5)==1,3))
rowindx = find(A(:,3)==minval)

カテゴリ

Help Center および File ExchangeInstrument Control Toolbox Supported Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by