I have a matrix x in matlab that has 6*n*n*3 rows and one column representing 6*n*n 3d coordinates of points. The coordinates are arranged such that rows 1:6*n*n are the x coordinates, rows 6*n*n+1:12*n*n are the y coordinates and 12*n*n+1:18*n*n are the z coordinates.
I would like to build 2 new matrices from it, one that simply places the x,y,z coordinates of a given point together and the other whose row i consists of subtracting point i to every other point.
Right now I am doing this using a double for loop which is very slow for n>16. Is there a better/faster way of doing this using matlab vector/matrix capabilities?
Here it is my current code
x=x(1:6*n*n);
y=y(6*n*n+1:12*n*n);
z=z(12*n*n+1:18*n*n);
N=6*n*n;
points=[];
difs=[];
for i=1:N
difrow=[];
points=[points;x(i) y(i) z(i)];
for j=1:N
deltax=x(i)-x(j);
deltay=y(i)-y(j);
deltaz=z(i)-z(j);
difrow=[difrow deltax deltay deltaz];
end
difs=[difs;difrow];
end