What does permute actually produce?

2 ビュー (過去 30 日間)
David H
David H 2014 年 11 月 20 日
編集済み: David H 2014 年 11 月 21 日
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 件のコメント
David H
David H 2014 年 11 月 20 日
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?

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2014 年 11 月 20 日
Isn't it
var2 = permute(var1,[3 2 4 1]);
?
  3 件のコメント
the cyclist
the cyclist 2014 年 11 月 20 日
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 2014 年 11 月 21 日
編集済み: David H 2014 年 11 月 21 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by