"Peter Schreiber" <schreiber.peter15@gmail.com> wrote in message <it4ltl$n6p$1@newscl01ah.mathworks.com>...
> for counter = 1:max_count
> A=(P5(:,counter)P4(:,counter))/norm(P5(:,counter)P4(:,counter));
> As=repmat(A',n_size_of ,1)  repmat(2*sum(N.*(repmat(A',n_size_of ,1)),2),1,3).*N;
> end
       
My guess is you are doing ray tracing off reflective surfaces and N is a set of 5000 unit normals to surface points. I guess further that you would actually like to have a max_count of 1000 instead of 10 since that is the size of P4 and P5 rows.
Your computation can be vectorized to produce a 3 x 5000 x 1000 3D array of (ray?) vectors using 'bsxfun' (similar to Matt's code) provided you have enough memory to store it. Otherwise you would have to cut down the 1000 to lower values, as you have done. Also I am not sure this would be any faster than something involving forloops, but you can test that yourself.
A = P5P4; % 3 x 1000
A = bsxfun(@rdivide,A,sqrt(sum(A.^2,1))); % 3 x 1000)
As = bsxfun(@times,reshape(N*(2*A),1,5000,1000),N.'); % 3 x 5000 x 1000
As = bsxfun(@minus,reshape(A,3,1,1000),As) % 3 x 5000 x 1000
Roger Stafford
