How do I find a specific x values in an array(?) of x,y locations?

30 ビュー (過去 30 日間)
Drew Ellington
Drew Ellington 2022 年 1 月 8 日
コメント済み: Chunru 2022 年 1 月 23 日
I'm able to create a matrix of x, y values ,
coordinates = [1,2; 3,4; 10,5; 4,5];
and use find(x), to search in the array,
find(coordinates == 10);
however once I attempt to use a bigger matrix this function doesnt seem to work and I dont understand why,
find(locations==143.4955);
returns an empty matrix but I know there are x values with 143.4955 in the matrix, can anyone help me?

採用された回答

Chunru
Chunru 2022 年 1 月 8 日
編集済み: Chunru 2022 年 1 月 23 日
% Now you have posted your data:
load('location array.mat')
whos
Name Size Bytes Class Attributes ans 1x43 86 char locations 2670x2 21360 single
% Your data is 2670x2
locations
locations = 2670×2
3.4017 263.0466 3.4017 263.0466 3.7207 87.7808 3.7207 87.7808 3.9423 249.8393 3.9423 249.8393 4.1351 96.5079 4.1351 96.5079 4.1892 83.5233 4.1892 83.5233
% floating point inside computer may not be exact
plot(locations(:,1)); hold on; plot(locations(:,2))
% Your data has values (in both columns) close to 143.4955
% In searching the closest points, you have to specify a suitable tolerance: 1e-4 below
% Search along the 1st column (you may have different criterion)
idx = find(abs(locations(:,1) - 143.4955) < 1e-4)
idx = 3×1
1284 1285 1286
locations(idx, :)
ans = 3×2
143.4955 158.7091 143.4955 158.7091 143.4955 158.7091
  2 件のコメント
Drew Ellington
Drew Ellington 2022 年 1 月 9 日
編集済み: Drew Ellington 2022 年 1 月 9 日
this is just returning the same empty column vector.....I need to return the index of the x values at 143.4955.....
Chunru
Chunru 2022 年 1 月 23 日
See the data with your posted data.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by