an Alternative funtion which is faster than "ismember"

9 ビュー (過去 30 日間)
Ahmet Hakan UYANIK
Ahmet Hakan UYANIK 2022 年 11 月 24 日
コメント済み: Bruno Luong 2022 年 11 月 24 日
Hello everybody,
I was using ismembertol with XY(Nx2) and xy(Mx2). However code never ends due to the enormous amount of data(N=400million M=80mil.).
Is there any way that I can speed this function. (The matrices are not unique)
[LIA,~]= ismembertol(XY,xy,0.00001,'ByRows',true,'OutputAllIndices',true);
Thank you for your support
  20 件のコメント
Ahmet Hakan UYANIK
Ahmet Hakan UYANIK 2022 年 11 月 24 日
I deeply appreciate the time and effort you took Bruno. It works perfectly without a loop which is amazing. I also would like to accept this answer but since it is in the comments, the botton does not apper.
Bruno Luong
Bruno Luong 2022 年 11 月 24 日
I post a short code as answer so you can accept it. Thanks

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

採用された回答

Bruno Luong
Bruno Luong 2022 年 11 月 24 日
If XY is gridded coordinates, then you can use discretize or simple division if they are uniform to determine which grid the river point belong to.
% Generate some toy fake data
xgrid = cumsum(randi(5,1,10))
x = min(xgrid)+rand(1,10)*(max(xgrid)-min(xgrid))
midpoints = (xgrid(1:end-1)+xgrid(2:end))/2;
x_edges = [-Inf midpoints Inf];
iclosest_x = discretize(x, x_edges)
xgridclosest = xgrid(iclosest_x);
d = abs(xgridclosest-x)
Do the same for y, then
LIA = false(length(ygrid),length(xgrid));
LIA(sub2ind(size(LIA), iclosest_y, iclosest_x)) = true;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by