MATLAB: How can I write a parallel code in Matlab

parallel computing in matlabParallel Computing Toolbox

hi every one, can you help me to write a program with parfor and compare the time consumed in comparing with for? The code is: matlabpool open local 7 tic parfor i = 1:100000 k=i end toc matlabpool close Elapsed time is 1.846197 seconds.
tic,for i = 1:100000 k=i end toc Elapsed time is 0.000640 seconds.

Best Answer

The reason you are seeing this result is because your loop does not do anything. If you make each iteration of your loop do substantial work, you will see a speedup.