|
"anyani himura" <colormason@att.net> wrote in message
news:jo3v48$asf$1@newscl01ah.mathworks.com...
> how do i time this loop A=randn(500);
> for i=1:500
> for j=1:500
> B(i,j)=sum(A(:,i).*A(:,j));
> end end
>
> i tried the following with tic toc but i get an enormous lines of timing.
> how do i get the single time taken for the whole process?
Don't put tic/toc around the body of the nested loops; put it around the
loops as a whole.
tic
> A=randn(500);
> for i=1:500
> for j=1:500
> B(i,j)=sum(A(:,i).*A(:,j));
> end end
toc
If for whatever reason you want to know how long each inner loop iteration
takes, call TOC with an output.
> A=randn(500);
times = zeros(500, 500);
> for i=1:500
> for j=1:500
tic;
> B(i,j)=sum(A(:,i).*A(:,j));
times(i, j) = toc;
> end end
--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
|