How can to compute the following case?
조회 수: 1 (최근 30일)
이전 댓글 표시
If there is a cell D and its size 6*9 and this cell contains matrices. (Attached)
in this line: svd(D{1,1}.'*D{1,2});
how can I change the indices of D to do the multiplication of all combinations of D but without repeat the similar combinations such as:
D{1,1}.'*D{1,2} and D{1,2}.'*D{1,1}
and exclude the similar indicies such as
D{1,1}.'*D{1,1} and so on ...
Then store all the results in "distance"
[U,S,V] = svd(D{1,1}.'*D{1,2});
distance = sqrt(sum(arrayfun(@(i)acos(S(i,i))^2,1:4)))
채택된 답변
Torsten
2023년 7월 18일
이동: Torsten
2023년 7월 18일
D = load("D.mat");
D = D.D;
n = size(D,1);
m = size(D,2);
distance = zeros(n,m,n,m);
for i=1:n
for j=1:m
for i1=1:n
for j1=1:m
[~,S,~] = svd(D{i,j}.'*D{i1,j1});
distance(i,j,i1,j1) = sqrt(sum(arrayfun(@(k)acos(S(k,k))^2,1:size(S,1))));
end
end
end
end
[M,I] = max(distance,[],'All')
[i,j,i1,j1] = ind2sub([n,m,n,m],I)
distance(6,9,6,8)
distance(6,8,6,9)
댓글 수: 0
추가 답변 (1개)
Chunru
2023년 7월 18일
load(websave("D.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1436693/D.mat"));
for i=1:size(D, 1)
for j=1:size(D, 2)
for i1=1:size(D, 1)
for j1=1:size(D, 2)
S{i,j,i1,j1} = D{i,j} - D{i1,j1};
end
end
end
end
whos
S{1, 2, 3, 4} % for example: D{1,2}-D{3,4}
댓글 수: 5
Torsten
2023년 7월 18일
Are you sure all cell matrices directions{i,j} have the same number of columns ? The distance formula only applies under this condition.
참고 항목
카테고리
Help Center 및 File Exchange에서 Numeric Types에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!