You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: permute.m
    path of file: ./repos/scGEAToolbox/tensor_toolbox/@ktensor
    
    the code of the file until where you have to start completion: function b = permute(a, order)
%PERMUTE Permute dimensions of a ktensor.
%
%   B = PERMUTE(A,ORDER) rearranges the dimensions of A so that they
%   are in the order specified by the vector ORDER. The output is a ktensor
%   with components rearranged as specified by ORDER. The corresponding
%   tensor has the same components as A but the order of the subscripts
%   needed to access any particular element is rearranged as specified by

    
function b = permute(a, order)
%PERMUTE Permute dimensions of a ktensor.
%
%   B = PERMUTE(A,ORDER) rearranges the dimensions of A so that they
%   are in the order specified by the vector ORDER. The output is a ktensor
%   with components rearranged as specified by ORDER. The corresponding
%   tensor has the same components as A but the order of the subscripts
%   needed to access any particular element is rearranged as specified by
%   ORDER.
%
%   See also KTENSOR.
%
%Tensor Toolbox for MATLAB: <a href="https://www.tensortoolbox.org">www.tensortoolbox.org</a>


N = ndims(a);

if ~isequal(1:N, sort(order))
    error('Invalid permuation');
end