Select from 2D Array by 2 criteria - Matlab

I have a 15 * 2 array where the first column represents the area and the second column represents the corresponding circularity to the 15 objects. I need to select the row with maximum area while applying the following condition for the circularity to be > 0.9 and <= 1.2
Example:
  • Area Circularity
  • ----- -----------
  • 22041 1,1703
  • 23458 2,8425
  • 155 1,4165
  • 37 2,1089
  • 215 1,5692
  • 41 1,0549
  • 659 1,7144
  • 64 1,0508
  • 3 0,3092
  • 584 1,2543
  • 26 1,1132
  • 396 2,9046
  • 1 0
  • 3 0,8488
  • 4 0,4638
  • Expected Result:
  • 22041 1,1703

 採用された回答

James Tursa
James Tursa 2017 年 3 月 15 日
編集済み: James Tursa 2017 年 3 月 15 日

1 投票

Try this:
y = your 2D matrix
x = y(:,2) > 0.9 & y(:,2) <= 1.2;
z = y(x,:);
[~,k] = max(z);
result = z(k,:);

その他の回答 (1 件)

Guillaume
Guillaume 2017 年 3 月 15 日
編集済み: Guillaume 2017 年 3 月 15 日

1 投票

filteredarray = yourarray(yourarray(:, 2) > 0.9 & yourarray(:, 2) <= 1.2, :); %filter unwanted rows
[~, maxrow] = max(filteredarray(:, 1)); %find location of max in what's left over
result = filteredarray(maxrow, :) %get the row at location

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

質問済み:

2017 年 3 月 15 日

編集済み:

2017 年 3 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by