extend a Matrix in every iteration
Mostrar comentarios más antiguos
Hi, I'm having some problems with my code. I have a 3 dimension matrix in which index represent a coordinate, for example, a 10x10x10 array where the first index are 1, 1, 1 represent the point x=1, y=1 and z=1. And the value in the array represent the number of points in theese coordinates. Now I want to use ptCloud function, so I have to extract all the points from my array. What I'm trying is this (If I were in the case 10*10*10 matrix A):
MAT=[]
for i=1:1000
[Yj Xj Zj]=ind2sub(size(A), i);
value=A(Yj Xj Zj);
P=[Yj Xj Zj];
P2=repmat(P,value,1)
MAT=[MAT;P2]
end
With this code I already have a matrix MAT whith every points. But the case is that my array is 200x200x160, and I noticed that in every iteration the time that the code requires increases a lot, so I think there would be something wrong in the for loop.
Thanks so much.
3 comentarios
jonas
el 18 de Mayo de 2018
The time for every iteration increases due to the size of MAT increasing with every iteration (can be fixed by preallocation). I don't understand what the desired output is, but I'm guessing there is a more effective way than a loop. What is MAT describing?
Fernando Arias
el 18 de Mayo de 2018
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Point Cloud Processing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!