Convert a symmetrical 4D array into a vector of it's degrees of freedom and vice-versa
1 view (last 30 days)
Show older comments
Michael Sheehan
on 7 Jan 2021
Commented: Michael Sheehan
on 7 Jan 2021
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.
0 Comments
Accepted Answer
Bruno Luong
on 7 Jan 2021
Edited: Bruno Luong
on 7 Jan 2021
% 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);
More Answers (0)
See Also
Categories
Find more on Data Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!