aykut <aykut_avci@hotmail.com> wrote in message <1284740095.251010.1288792734046.JavaMail.root@gallium.mathforum.org>...
> Hi experts,
>
> I have a loop which I need to run many times. Therefore, I am looking for a faster solution, if possible. Basically, I have a matrix and I need to write it down in a file as formatted. every increment of i value, texta takes the values from the matrix and adds it at the end of itself. I think string adding by using [a, b] is a bit slow solution for that. Could you please give me a hand?
>
> texta='';
> for i=1:4:b
> texta=[texta, sprintf('%d\n%d %d %d\n%d %d %d\n%d %d %d\n%d %d %d\n',(i1)/4+1,TempMotionVect(1,i), TempMotionVect(2,i),TempMotionVect(3,i),TempMotionVect(1,i+1), TempMotionVect(2,i+1),TempMotionVect(3,i+1),TempMotionVect(1,i+2), TempMotionVect(2,i+2),TempMotionVect(3,i+2),TempMotionVect(1,i+3), TempMotionVect(2,i+3),TempMotionVect(3,i+3))];
> end
preallocate a cell array:
C = cell(length(1:4:b),1)
on each loop iteration right your long thing to it
for jj = 1:length(1:4:b)
ii = jj*4+1
C{jj} = your long expression(ii)
end
Then unpack your cell, C as necessary.
