How can I layer coordinate matrixes into a cell of vectors? (iteration over matrices)

6 views (last 30 days)
I have 3 matrices of coordinates, say:
x=[1,2;1,2] , y=[1,1;2,2] , z=[5,6;7,8]
I want to somehow combine them to get a cell that holds at each spot a 1X3 double of the vector at that spot, as in:
A= [1,1,5] [2,1,6] ;
[1,2,7] [2,2,8]
the following doesn't work:
A(:,:)=[x(:,:),y(:,:),z(:,:)]
I tried layering the matrixes:
temp=cat(3,x,y,z)
a={permute(temp(1,2,:),[2,3,1])}
R=cell(2,2)
R(1,1)=a
but this will only give me a single vector, and i want to do this at every index over a large matrix (without using loops as it becomes very slow)
(I want to be able to keep the vectors 'next' to their original neighbours, so please don't tell me to 'spread' the data into a 3*n matrix as then I would lose that information)
anyone know a good way to iterate over the matrices? thanks in advance!

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 10 May 2013
Edited: Azzi Abdelmalek on 10 May 2013
x=[1,2;1,2];
y=[1,1;2,2];
z=[5,6;7,8];
A=arrayfun(@(a,b,c) [a b c],x,y,z,'un',0)

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!