What does permute actually produce?

2 visualizaciones (últimos 30 días)
David H
David H el 20 de Nov. de 2014
Editada: David H el 21 de Nov. de 2014
Trying some calculations earlier, I have realised permute does not do what I thought it did. To clarify I did this
% code
test = rand(4,4,4,4) + rand(4,4,4,4)*1i;
test2a = zeros(4,4,4,4); test2b = zeros(4,4,4,4);
for a = 1:4
for b = 1:4
for c = 1:4
for d = 1:4
test2a(a,b,c,d) = test(a,b,d,c);
test2b(a,b,c,d) = test(b,a,c,d);
end
end
end
end
test3a = permute(test,[1,2,4,3]);
test3b = permute(test,[2,1,3,4]);
m1=max(test2a(:)-test3a(:))
m2=max(test2b(:)-test3b(:))
test2a = zeros(4,4,4,4); test2b = zeros(4,4,4,4);
for a = 1:4
for b = 1:4
for c = 1:4
for d = 1:4
test2a(a,b,c,d) = test(d,b,a,c);
test2b(a,b,c,d) = test(c,a,b,d);
end
end
end
end
test3a = permute(test,[4,2,1,3]);
test3b = permute(test,[3,1,2,4]);
m3=max(test2a(:)-test3a(:))
m4=max(test2b(:)-test3b(:))
m1 =
0
m2 =
0
m3 =
0.9525 + 0.5183i
m4 =
0.9293 - 0.7266i
clearly the first is the same but the latter is different. Is there some way to create the second variables (of form test2(a,b,c,d) == test(d,b,a,c) which involve two permutations ) just using permute on test?
  1 comentario
David H
David H el 20 de Nov. de 2014
I realise reading this again I haven't really stated what I want to do very clearly.
If I want some variable satisfying var2(a,b,c,d) == var1(d,b,a,c) for any a b c d (up to the size of the variable) how do I produce this variable efficiently from var1?

Iniciar sesión para comentar.

Respuesta aceptada

the cyclist
the cyclist el 20 de Nov. de 2014
Isn't it
var2 = permute(var1,[3 2 4 1]);
?
  3 comentarios
the cyclist
the cyclist el 20 de Nov. de 2014
Here is the reasoning:
  • The former dimension 3 is now dimension 1.
  • The former dimension 2 is now dimension 2.
  • The former dimension 4 is now dimension 3.
  • The former dimension 1 is now dimension 4.
So, you see that new dimension [1 2 3 4] is old dimension [3 2 4 1].
That latter vector is the one you needed.
David H
David H el 21 de Nov. de 2014
Editada: David H el 21 de Nov. de 2014
Ah yes I was thinking on the lines of:
  • The new dimension 1 is dimension 4,
  • The new dimension 2 is dimension 2,
  • new dimension 3 is dimension 1 etc
rather than this way round, which is of course not the values you call permute with!
Thanks for the clarification, I realise it was a fairly nieve mistake.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by