clc;clear;close all;

N=4;    % Number of your CPU core, in my case, 4
matlabpool(N) % open N multicores for the parallel computation
tic
spmd    % similar with for loop 
  for i=1:50    % complex computation
      A=rand(1000);
      B=inv(A);
      C(i)=norm(B);
  end
end
for i=1:4   % important!!! 
            % before the endo of matlabpool statement, 
            % you should store the variable which you want to use, 
            % or you will lose the variable
    D{i}=C{i};
end
toc
matlabpool close    % you must close the multicore calculation statement

clear;
tic
for j=1:4
  % build magic squares in parallel
  for i=1:50
      A=rand(1000);
      B=inv(A);
      C{j}(i)=norm(B);
  end
end
toc