blob: 61910705423287a1a1b773330fa47d84a29ae21b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
function S_permuted = xpxp_to_xxpp(S)
% Permutes the entries of the input from xpxp ordering to xxpp ordering.
%
% Args:
% S (array): input even dimensional square matrix or a row vector
%
% Returns:
% S_permuted (array): permuted matrix or vector
shape = size(S);
if length(shape) > 2
error('The input matrix is not 2 dimensional');
end
n = shape(2);
if mod(n, 2) ~= 0
error('The input array is not even-dimensional');
end
n = n / 2;
ind = reshape(1:2*n, 2, [])';
ind = ind(:)';
if shape(1) == shape(2)
S_permuted = S(ind, ind);
else
S_permuted = S(ind);
end
end
%!test
%! [X, Y]=meshgrid (1:4, 1:4);
%! Mxpxp=xxpp_to_xpxp(X);
%! assert(any(any(X != Mxpxp)));
%! Mxxpp=xpxp_to_xxpp(Mxpxp);
%! assert(X, Mxxpp)
%! Mxpxp=xxpp_to_xpxp(Y);
%! assert(any(any(Y != Mxpxp)));
%! Mxxpp=xpxp_to_xxpp(Mxpxp);
%! assert(Y, Mxxpp)
|