The permutation operation needs to output a different matrix to the output, it's not like reshape
, where the data is not modified, permute
does modify the data.
However, if one tests the memory usage of a multidimensional permutation, it's the same as the variable used. So, my question is, how does MATLAB execute this permutation in order to avoid using any extra memory?
Extra question: Is there any scenario in which MATLAB actually uses extra memory?
Test code:
function out=mtest()
out = ones(1e3,1e3,1e3); % Caution, 8Gb
out=permute(out,[3 1 2]);
end
Call this with:
profile -memory on
a=mtest;
profreport
CAUTION, its 8Gb of data.