vectorization of (tic toc in for loop)

A=rand(1000,1000,5);
B=rand(1000,1);
m=0;
i=1:5;
tic;
X=zeros(1000,size(A,3));
X(:,size(A,3))=A(:,:,size(A,3))\B;
m(i)=toc;
m
Mean=mean(m)
Var=var(m)
Std=std(m)
Mode=mode(m)
Min=min(m)
Max=max(m)
Is this the vectorization that without for loop? The toc are same for each repetition. How should I do to get different toc each time the answer for mean, mode, min, max are equal. How should I modified the t/ic toc without loop

2 Comments

Modify it for what purpose?
Your code does exactly the same thing in each loop iteration, so differences in timing would be expected to be small provided that your operating system is not interrupting for some other task. What is it that you would like to vectorize ?
I would like to vectorize the tic toc and X=A\B function as vectorization means to remove for loop 1.Repeat this procedure(solve 1000x1000 system of linear equations use tic toc) 500 times using a for loop and measure the following statistical properties of the time required to solve the system of equations using the tic, toc timing function. variance and standard deviation, minimum, maximum, mode and mean 2.re-write the code for (1) using techniques such as vectorization and preallocation to speed up your MATLAB code performance. Examine if there is any improvement in the performance of your code. Comment on the magnitude of the improvement. If you do not notice any significant improvement in performance, give a possible reason why this could be so

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 17 Apr 2014

Edited:

on 22 Apr 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!