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