intersections of all combinations of pairs of matrices in 3D array
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, I have a 3D array "array_ellipsoid" of size(40000,3,5000). this array represents 5000 ellipsoids that intersect in 3D space. I need to find the intersection between all combinations of pairs of matrices in this array. for example, A=array_ellipsoid(:,:,1), B=array_ellipsoid(:,:,2), C=array_ellipsoid(:,:,3),...., Z=array_ellipsoid(:,:,5000), then I need to get an array to get all possible intersections between "A,B" and "A,C" and "B,C",etc... for all combined pairs. I already do this by nested for and if loops but it takes huge processing time. I was wondering if there is a faster and smarter way to do it in shorter time and avoid the unnecessary nested loop processing time consumption.Please find below the sample code.thanks in advance.
intersect_pts=30;
array_intersect=nan(intersect_pts,3,5000,5000);
load('D:\array_ellipsoid.mat')
for i=1:5000
for j=1:5000
if i~=j
intersect_data=intersect(array_ellipsoid(:,:,i),array_ellipsoid(:,:,j),'rows');
if isempty(intersect_data)==0 && size(intersect_data,1)<=intersect_pts
array_intersect(1:size(intersect_data,1),:,i,j)=intersect_data;
elseif isempty(intersect_data)==0 && size(intersect_data,1)>intersect_pts
array_intersect(:,:,i,j)=intersect_data(1:intersect_pts,:,:);
end
end
end
array_intersect_final=permute(reshape(permute(array_intersect,[2 1 3 4]),[3 intersect_pts*5000*5000]),[2 1 3]);
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!