Convert a symmetrical 4D array into a vector of it's degrees of freedom and vice-versa

1 次查看(过去 30 天)
I was looking for an efficient way to convert a 4D-array 𝒜 that is symmetric, such that for all index permutations p, into a vector of it's degrees of freedom i.e. just the single entry for the whole of . This should be a map from size to . How would I also find the opposite map so given the vector of the degrees of freedom I would like to map this to a 4D array 𝒜.
Thank you in advance.

采纳的回答

Bruno Luong
Bruno Luong 2021-1-7
编辑:Bruno Luong 2021-1-7
% A = zeros(7,7,7,7);
n = length(A); % 7
m = ndims(A); % 4
C = cell(1,m);
[C{:}] = ndgrid(1:n);
I = reshape(cat(m+1,C{:}),[],m);
[I,~,J] = unique(sort(I,2),'rows');
subs = num2cell(I,1);
szA = n + zeros(1,m);
I = sub2ind(szA,subs{:});
% Extract nchoosek(n+m-1,m) unique-represented elements of A
Acompact = A(I);
% Get back A from Acompact.
% Acompact of length nchoosek(n+m-1,m)
% Acompact(k) coresponds to A having subindex I(k,:), k=1,2,... choosek(n+m-1,m)
A(:) = Acompact(J);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by