I'm trying to build a structure consisting of elements which are column vectors representing x, y, z points. So far, I have written the following code, which indexes arrays representing x, y, z positions of points from a structure called 'data' (derived from a .ply 3d graphics file) and rearranges them into a 3 x n matrix:
% orders vertex data from structure into column vectorsx = data.vertex.xy = data.vertex.yz = data.vertex.z% vertically concatenates x, y, z to form a 3 x n matrix stored in the% structure, vertsverts = horzcat(x, y, z)%Sequentially indexes PX PY PZ into a 3 x n matrix where columns are x y z%components of position vectorsfor i=1:length(x)vertsnew(:,i)=[x(i);y(i);z(i)];end
This creates a matrix of the form:
3.7427 3.74984 1.389034.7384 3.76483 8.762899.6389 9.62843 5.78290 .............
I want to create a structure where each column vector in this array is a seperate element. I thought the following might do the trick:
vertz=struct();for k=1:size(x)Vk = [vertsnew(1,k)];vertz.(['VZ' num2str(k)])=Vk;end
But this results in a structure with x, y, z arranged sequentially as individual elements. E.g:
vertz.VZ.1 = 3.7427vertz.VZ.2 = 4.7384vertz.VZ.3 = 9.6389
I am able to create individual column vectors using:
%Orders arrays, into discrete column vectorsfor i=1:length(x)assignin('base',['vertv' num2str(i)],[x(i);y(i);z(i)])end
vertv1 = 3.7427vertv2 = 4.7384
Though I am unsure how to obtain the desired structure from these seperate arrays. Any help would be greatly appreciated.