an Alternative funtion which is faster than "ismember"

3 visualizaciones (últimos 30 días)
Ahmet Hakan UYANIK
Ahmet Hakan UYANIK el 24 de Nov. de 2022
Comentada: Bruno Luong el 24 de Nov. de 2022
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 comentarios
Ahmet Hakan UYANIK
Ahmet Hakan UYANIK el 24 de Nov. de 2022
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 el 24 de Nov. de 2022
I post a short code as answer so you can accept it. Thanks

Iniciar sesión para comentar.

Respuesta aceptada

Bruno Luong
Bruno Luong el 24 de Nov. de 2022
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;

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by