Does the permute function have a bug?

2 visualizzazioni (ultimi 30 giorni)
Hi, when i use the permute function to shift dimensions of a four-dimension array, it has:
K>> U=randn(2,300,150,1000); U=permute(U,[4 1 2 3]); size(U)
ans =
1000 2 300 150
Why it doesnot shift the first dimension to forth dimension. Am i wrong or it is the issue of permute function. The matlab version is R2019b. Thanks!

Risposta accettata

David Goodmanson
David Goodmanson il 5 Dic 2019
Modificato: David Goodmanson il 5 Dic 2019
Hello ZY,
see 'help permute'. Permute puts the dimensions in the order listed, so in this case the old 4th dimension goes first, old first dimension goes second, etc.
It could have been that each dimension goes to the dimension specified in its original slot, so that the first dimension goes fourth, the second dimension goes first. etc. That is a legit and consistent way of doing things, but it's not how it was done.
  2 Commenti
Stephen23
Stephen23 il 5 Dic 2019
"Permute puts the dimensions in the order listed"
Just like indexing, which is interpreted in the same way: elements (or rows/columns/pages/...) are put into the order listed by the index. So permute is perfectly consistent with this.
Steven Lord
Steven Lord il 5 Dic 2019
Not only is that alternate interpretation a "legit and consistent way of doing things", it is the way that ipermute works. Showing this with a slightly smaller array:
>> U = ones(2, 3, 4, 5);
>> v = [4 1 2 3];
>> size(U)
ans =
2 3 4 5
>> size(permute(U, v))
ans =
5 2 3 4
>> size(ipermute(U, v))
ans =
3 4 5 2

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by