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)))

2 commentaires

Chunru
Chunru le 18 Juil 2023
Can you give an example of your data D?
M
M le 18 Juil 2023
@Chunru I attached the file

Connectez-vous pour commenter.

 Réponse acceptée

Torsten
Torsten le 18 Juil 2023
Déplacé(e) : Torsten le 18 Juil 2023
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')
M = 1.5695
I = 2592
[i,j,i1,j1] = ind2sub([n,m,n,m],I)
i = 6
j = 9
i1 = 6
j1 = 8
distance(6,9,6,8)
ans = 1.5695
distance(6,8,6,9)
ans = 1.5695

Plus de réponses (1)

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
Name Size Bytes Class Attributes D 6x9 15984 cell S 6x9x6x9 863136 cell cmdout 1x33 66 char i 1x1 8 double i1 1x1 8 double j 1x1 8 double j1 1x1 8 double
S{1, 2, 3, 4} % for example: D{1,2}-D{3,4}
ans = 6×4
-0.0068 0.1359 0.2272 0.2585 -0.5386 0.0657 0.4552 0.5899 0.2370 0.1540 0.0995 0.0803 0.1061 0.0122 -0.0485 -0.0696 0.0210 -0.0793 -0.1435 -0.1655 -0.0087 -0.1109 -0.1761 -0.1985

5 commentaires

M
M le 18 Juil 2023
Modifié(e) : M le 18 Juil 2023
@Chunru thanks, but I have a question please I used your code for multiplication all the combinations then I used it to compute 'distnace' and distance should give one value, but I have a problem how can I store all the distance values in a right way. can you please check?
also I am not getting only single values.
for i=1:size(D, 1)
for j=1:size(D, 2)
for i1=1:size(D, 1)
for j1=1:size(D, 2)
[U,S,V] = svd(D{i,j}.'*D{i+1,j+1});
distance{i,j,i1,j1} = sqrt(sum(arrayfun(@(i)acos(S(i,i))^2,1:4)))
end
end
end
end
[U,S,V] = svd(directions{i,j}.'*directions{i,j});
This makes no sense. If you use identical directions to compare, you'll of course get a distance of 0 for every pair.
M
M le 18 Juil 2023
@Torsten I will ignore the zero value, I want to get all the distance between the other combinations
Torsten
Torsten le 18 Juil 2023
Are you sure all cell matrices directions{i,j} have the same number of columns ? The distance formula only applies under this condition.
M
M le 18 Juil 2023
Hi @Torsten, I edited the question, could you please suggest a solution

Connectez-vous pour commenter.

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by