On Sat, Sep 24, 2011 at 2:38 PM, Torbjörn Rathsman <address@hidden>
How do I vectorize this piece of code?
a is an NDArray
v=[a(i,j,1) a(i,j,2) a(i,j,3)]';
I don't have time to double check it right now, but I think you might want to use the "arrayfun" function. Something like:
A = rand(3);
f = @(x,y,z)A\[x;y;z];
b = arrayfun(f, a(:, :,1), a(:,:,2), a(:, :,3), "UniformOutput", false);
Will return a cell array where b(i,j) = a(i,j,:).
Not sure if this works perfectly, but hopefully it at least points you in the right direction.