image thumbnail
from Getting Started with Parallel Computing using MATLAB by Arjav Chakravarti
This is an older version of the introductory tutorial for running parallel MATLAB applications

parforExample1.m
matlabpool open 2 % can adjust according to your resources

N = 100;
M = 200;
a = zeros(N,1);

tic;   %  serial (regular) for-loop
for i = 1:N        
    a(i) = a(i) + max(eig(rand(M)));
end
toc;

tic;   %  parallel for-loop
parfor i = 1:N
    a(i) = a(i) + max(eig(rand(M)));
end
toc;
 
matlabpool close

Contact us at files@mathworks.com