Clear Filters
Clear Filters

Speed up triple 'for' loop with parfor

1 view (last 30 days)
Fotaras Sitof
Fotaras Sitof on 28 Feb 2016
Commented: Jan on 28 Feb 2016
Dear Matlab users,
I have a 4D dataset of images [360x360x30x20] corresponding to (x,y,z,t) dimensions, with x and y being the pixel coordinates, z the slice and t time. I need to extract the pixel values along the 4th dimension (t) and then use them in further calculations. Currently, I'm using a triple 'for' loop for the extraction and a cell array to store the values. The stored values are then used in further calculations and the results are saved in another cell array B. This loop is rather slow, so I was wondering how to use a 'parfor' loop instead. It seems that I can only replace the innermost 'for' with 'parfor', but I'm not sure if that's the best way to proceed. Any suggestions are greatly appreciated.
for i=1:x
for j=1:y
for k=1:z
A{i,j,k}=squeeze(data(i,j,k,:));
% calculations using the stored values in A
% results stored in cell array B
end
end
end
  1 Comment
Jan
Jan on 28 Feb 2016
What does the profiler tell you about the bottlenecks? Is A preallocated properly?

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!