an Alternative funtion which is faster than "ismember"

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by