フィルターのクリア

Is there an alternative to "find" for non-integer values?

5 ビュー (過去 30 日間)
Brian
Brian 2013 年 5 月 7 日
Hi,
I need to find all the coordinates in a nx2 matrix which have a certain (x) value. All the coordinates are non-integer so find will not work.
Example:
M = 2.334 3.554
4.443 4.554
3.245 5.332
4.443 2.443
Is there a way to put [4.443 4.445; 4.443 2.443] into a new matrix? Can num2string and back again work or is there a better way? Thanks in advance

採用された回答

Image Analyst
Image Analyst 2013 年 5 月 7 日
編集済み: Image Analyst 2013 年 5 月 7 日
Check if it's within a tolerance, as recommended by the FAQ. Try this:
targetValue = 4.443;
tolerance = 0.01;
M = [2.334 3.554
4.443 4.554
3.245 5.332
4.443 2.443]
diffM = abs(M(:, 1) - targetValue)
% Find rows within tolerance of the target value in row 1.
rowsToExtract = diffM < tolerance
% Extract only those rows:
extractedRows = M(rowsToExtract, :)
In the command window you'll see:
M =
2.334 3.554
4.443 4.554
3.245 5.332
4.443 2.443
diffM =
2.109
0
1.198
0
rowsToExtract =
0
1
0
1
extractedRows =
4.443 4.554
4.443 2.443
  1 件のコメント
Brian
Brian 2013 年 5 月 7 日
That's brilliant, thanks very much

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by