Azzera filtri
Azzera filtri

Speed up triple 'for' loop with parfor

1 visualizzazione (ultimi 30 giorni)
Fotaras Sitof
Fotaras Sitof il 28 Feb 2016
Commentato: Jan il 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 Commento
Jan
Jan il 28 Feb 2016
What does the profiler tell you about the bottlenecks? Is A preallocated properly?

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by