I am looking for an equivalent of permute(A,dimorder) from Matlab, in order to convert some Matlab code to R.
A loop entails a line that looks something like this:
x = permute(a{i}(b(i,ii),:,:,:,:,:),[2 3 4 5 6 1])
The cell array structure e.g. a{1}(1,:,:,:,:,:) results in selecting the first row of matrices within the cell array a{}. [2 3 4 5 6 1] in permute() refers to the dimorder.
The documentation for the matlab function permute() including example output can be found here:
https://de.mathworks.com/help/matlab/ref/permute.html
There are several functions in R referring to permutation in some way or another, but non of them seemed to be what I am looking for, though I may have gotten something wrong.
I believe I successfully replicated the MATLAB script in R. I don't think you actually need an equivalent for
permute. In the MATLAB script,permuteappears to be simply dropping excess dimensions. R does that by default unless you specifydrop = FALSEwhen you subset an array, e.g.,If I add
lnA = cell(T, NumModalities);to the MATLAB script before your finalforloop and then modify the inside of the loop to beThen I get the same array of matrices in
lnAfor both the MATLAB and R implementations.In R, I use an array of lists as the equivalent of a MATLAB 2+ dimension cell array:
Here's the implementation: