# MATLAB: Inefficient or slow use of colon-operator within a matrix

:array dimensioncolon

Dear all,
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.
Kees

Data2 = Data;
Data3 = Data(:, :, :, 1);
Data3(1) = 2;
Data2(1) = 2;
>> tic; Data2(1) = 2; tocElapsed time is 0.478432 seconds.>> tic;Data3(1) = 2; tocElapsed time is 0.000584 seconds.