Double loop sort and group results in one matrix
1 次查看(过去 30 天)
显示 更早的评论
I have two matrices X and Y, both 3x100 columns. I am performing some operation between the elements (cartesian distance, not important for this problem), and each step gives 1x100 vector/matrix. Each of the element in X performing an operation on each of the elemt on Y. So X(1) gives a 1x100 vector/matrix. I have to repeat it for all 100 element of X, so I should get a 100x100 matrix. I have the below code, what can I do to get that 100x100 matrix.
L = length(X);
for i=1:L
for j=1:L
X(i)= sqrt((X(j,1)-Y(i,1))^2 + (X(j,2)-Y(i,2))^2 + (X(j,3)-Y(i,3))^2);
X(i) = X(i)/10;
end
end
0 个评论
回答(1 个)
Prateek Rai
2021-11-21
Hi,
A possible workaround to solve the problem could be:
Z = zeros(100,100);
L = length(X);
for i=1:L
for j=1:L
Z(i,j) = sqrt((X(1,j)-Y(1,i))^2 + (X(2,j)-Y(2,i))^2 + (X(3,j)-Y(3,i))^2);
Z(i,j) = Z(i,j)/10;
end
end
Here, Z the 100x100 matrix.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!