Hi,
you are right, inside the loop and inside the brackets, a
multiplication of a matrix with a scalar takes place. You
can find this also from the definitions in the first line
of my post.
I will check if bsxfun will help. With all this repmat, i
suspect that this will be too time consuming to reserve all
that memory.
Thank you for your reply.
Best regards,
Johannes
roberson@ibd.nrccnrc.gc.ca (Walter Roberson) wrote in
message <fpbreh$5pm$1@canopus.cc.umanitoba.ca>...
> In article <fpbbbk$q97$1@fred.mathworks.com>,
> Johannes Korsawe <johannes.korsawe.nospam@volkswagen.de>
wrote:
>
> >Let be size(I)=[1 201], size(poly)=[1,n+1], size(X)=
[3,n+1].
>
> >With this, i have the following loop:
>
> >line=0*[I;I;I];
> >for i=0:n,
> > line=line+[X(1,i+1)*poly{i+1};X(2,i+1)*poly{i+1};X
(3,i+1)
> >*poly{i+1}];
> >end
>
> >How can i accelerate this loop? Is there any possibility
of
> >vectorizing this statement?
>
> Could you clarify whether poly is a cell array with n+1
elements,
> each of which is a vector of 201 numbers? And that X is an
> ordinary numeric array, so X(k,i) * poly{i+1} is
> a scalarvector multiplication, not a matrix
multiplication?
>
> If so, then I think replacing the loop body with
> line = line + bsxfun(@times, poly{i+1}, X(:,i+1))
> might work  but might not be faster.
>
> To improve... let's see... cell2mat(poly) would be (n+1)
x 201,
> repmat that to 3 x (n+1) x 201, repmat X to 3 x (n+1) x
201,
> use .* to multiply the two, sum along the second
dimension, then
> if need be, ipermute the 3 x 1 x 201 to 3 x 201 x 1. Or
do the
> repmat's slightly differently so you end up summing along
the
> last dimension so you automatically get 3 x 201 out of it.
> 
> "When a scientist is ahead of his times, it is often
through
> misunderstanding of current, rather than intuition of
future truth.
> In science there is never any error so gross that it
won't one day,
> from some perspective, appear prophetic."  Jean
Rostand
