work around for sparse matrices in 3D
显示 更早的评论
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?
回答(2 个)
Sean de Wolski
2012-1-20
1 个投票
FEX:ndSparse This is well rated.
Mike
2019-9-11
0 个投票
Never mind, I just found ndSparse, which seems to do what I wanted.
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!