From: Jorian on
"Juliette Salexa" <juliette.physicist(a)gmail.com> wrote in message <h3bd1h$86h$1(a)fred.mathworks.com>...
> I've been told to avoid forloops in matlab because they're extremely slow.
> consider this:
>
> clear('cap')
> tic;
> cap=ones(15,1);
> for i=1:15
> cap(i)=2;
> end
> toc;
>
> clear('cap')
> tic;
> cap=ones(15,1);
> cap(:)=2;
> toc;
> %%
>
>

This is the loop rule for Matlab

Best regards, Jorian Seokaner!

http://www.mathworks.com/matlabcentral/newsreader/author/126323
> Elapsed time is 0.000088 seconds.
> Elapsed time is 0.000017 seconds.
>
> What is matlab DOING when we do cap(:)=2, is it not a for loop ?? it's more than 4x faster than a for loop.