work around for sparse matrices in 3D
Show older comments
I'm busy making huge clusters with off lattice diffusion limited aggregation. For efficiency I use a grid where I put the number of the particle on it's rounded off position. I 2D I can use a sparse matric for this, and I look if there are particles near a certain position with find on a part of this sparse matrix. Now I want to go to 3D and matlab doesn't support 3D sparse matrices. Using a full 3D matrix is not an option, I need at least a uint32 2000x2000x2000 matrix using 3.2gb of memory. So I'm looking to make a work around with a sort of sparse triplet variant in 3d, so 4 vectors with x,y and z positions and the values. The problem now is to locate the nonzero values in an efficient way. When I am for example in position [10,10,10] i want to know all nonzeros in the region [5:15,5:15,5:15]. Using something like: val=A(A(:,2)>5 & A(:,2)<15 & A(:,3)>5 & A(:,3)<15 & A(:,4)>5 & A(:,4)<15); with A=[values x y z] works, but it is terribly slow. I also tried a similar statement with find but it was equally slow.
Anyone has an idea?
Answers (2)
Sean de Wolski
on 20 Jan 2012
1 vote
FEX:ndSparse This is well rated.
Mike
on 11 Sep 2019
0 votes
Never mind, I just found ndSparse, which seems to do what I wanted.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!