From: Andy on 8 Jul 2010 14:38 My incorrect code is as follows, can you tell me where I am going wrong? C=[]; for x=1:64 for y=1:64 for z=1:64 coords=cat(2,x,y,z); C(x,y,z)=cat(3, C, coords); end end end
From: Jan Simon on 8 Jul 2010 14:50 Dear Andy, > One last thing, how do I create a [64^3x3] matrix? C = zeros(64, 64, 64); > I was trying to create a [64x64x64] matrix which just consisted of strings representing the coordinates but that did not work? Strings?! Strings are vectors of characters like 'hello' -- not suitable for representing coordinates. Jan
From: Andy on 8 Jul 2010 15:04 > Strings?! Strings are vectors of characters like 'hello' -- not suitable for representing coordinates. How then do I allow the elements of my matrix to each have an x, y, and z value? With zeros I can create the array, but can't correctly add in the proper coordinates to replace the 0 in each position.
From: Jan Simon on 8 Jul 2010 15:17 Dear Andy, > C = zeros(64, 64, 64, 3); % !!! ever preallocate !!! > for x=1:64 > for y=1:64 > for z=1:64 > C(x, y, z, 1:3) = [x, y, z]; > end > end > end This could be reshaped finally: C = reshape(C, 64^3, 3); Inspect the values of C (a smaller size would be helpful). Then you will see, that there are much more efficient and nicer method to create C. Kind regards, Jan
From: Andy on 8 Jul 2010 16:30 Jan, Thank you so much that works great! However when I attempt to multiply it by the rotation matrix it won't let me because the dimensions don't agree. I tried making individual x, y, and z matricies of C such that Cx=squeeze(C(:,1,1,:)) These I can multiply by my 2D rotation matrix but it appears I am missing some values because I end up with a 64x3 array for each, which gives a total of 576 values, substaintially less than the 786432 I would expect in a 64x64x64x3 matrix like I started with. I'm sorry that I have so many questions, I'm still not very adept with the multidimensional array manipulations. Thanks again!
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Why do Image Size Dimensions Change Next: Monitoring external executable output |