MATLAB: For-loop vectorization and structure

for loopMATLABstructurevectorization

Hello all,
I've tried to vectorize the following for-loop:
for i=1:ne
S(1,i).P(1,1).x = [v_proj(fv(i,1),1) v_proj(fv(i,2),1)
v_proj(fv(i,3),1)];
S(1,i).P(1,1).y = [v_proj(fv(i,1),2) v_proj(fv(i,2),2)
v_proj(fv(i,3),2)];
S(1,i).P(1,1).hole = 0;
end
But unfortunately I did not manage to do so. I've tried what follows:
S(1:ne).P.x = [v_proj(fv(1:ne,1),1) v_proj(fv(1:ne,2),1) v_proj(fv(1:ne,3),1)];
Even though everything turns out to be correct for the right-hand side, it does not work for the left one as I would have expected. Can anyone help? Because I really need to feed this structure in a more efficient way and increase original poor speed of the algorithm.
Thank you very much for your help,
Regards,
% Romain

Best Answer

t = mat2cell( [v_proj(fv(1:ne,1),1) v_proj(fv(1:ne,2),1) v_proj(fv(1:ne,3),1)], ones(1,ne), 3);
[S(1:ne).P.x] = t{:};
This is not tested but it looks about right.