问题
I need to write in Matlab this portion of the package "tensor" which is written in R. Unfortunately I am not used to R code style.
where A=matrix(sample(0:1, 2 * 3, replace = TRUE), 2, 3)
here the code in R:
A <- as.array(A)
dimA <- dim(A)
dnA <- dimnames(A)
seqA <- seq(along=dimA)
allA <- length(seqA) == length(alongA)
permA <- c(seqA[-alongA], alongA)
if (!all(seqA == permA))
A <- aperm(A, permA)
dim(A) <- c(
if (allA) 1 else prod(dimA[-alongA]),
prod(dimA[alongA])
)
Thank you in advance for your help!
回答1:
alongA is undefined; the R code is incomplete. could you provide a working sample?
来源:https://stackoverflow.com/questions/46457760/convert-r-code-into-matlab