I'm struggling with the performance of my code for a while. I just found out the big issue.
It appeared that the use of colon-operator within a matrix (to include all subscripts in a particular array dimension) is incredibly slow or inefficient:
Data = ones(500,500,500);clear Data2 Data3;ticData2 = Data;toc; %--> Elapsed time is 0.006142 seconds.ticData3 = Data(:,:,:,1);toc; %--> Elapsed time is 0.430237 seconds.
Why is the use of ":" / Colons 70 times (!!) slower. Is there a solution to give this a boost? I need the flexibility of "Data(:,:,:,d)" since in some cases my data is multidimensional.
Many thanks in advance. Looking forward to your response.