Using Logical Indexing with Matrices
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello,
I am currently working on something where I have a large number of three dimensional points (8.9e7 points) expressed in a matrix like X=[x;y;z] where x, y, and z are row vectors containing the Cartesian coordinates of each point.
I need to search these points and pull out sets of points that fall on a given plane with a tolerance and store these points to a new matrix like X2=[x2;y2;z2] where x2, y2, and z2 are points from X that fall on the defined plane.
I have tried something like this:
%generating spherical point cloud
n=8937*10000;
L=sqrt(n*pi());
k=1:n;
z=ones(size(k))-(2*k-ones(size(k)))./n;
phi=acos(z);
theta=L*phi;
x=sin(phi).*cos(theta);
y=sin(phi).*sin(theta);
rbody=1737; alt=50;
X=[x*rbody;y*rbody;z*rbody];
%defining plane
ns=[1,1,1]; %normal vector
planeloc=rbody^2/(alt+rbody); %distance from origin
%Storing values that fit on the plane
X2=X(ns*(X-planeloc*ns'*ones(1,length(x)))>=-0.0001 & ns*(X-planeloc*ns'*ones(1,length(x)))<=0.0001);
max(max(X2)) %testing to see if any values fit
but it does not perform what I want. When I use the logical index
X(ns*(X-planeloc*ns'*ones(1,length(x)))>=-0.0001 & ns*(X-planeloc*ns'*ones(1,length(x)))<=0.0001)
because the index returns values for each element of the matrix. Is there some way that I can use logical indices to select the columns of X that satisfy
(ns*(X-planeloc*ns'*ones(1,length(x)))>=-0.0001 & ns*(X-planeloc*ns'*ones(1,length(x)))<=0.0001)
without running a for loop (which would obviously take forever due to the huge number of points).
Thanks, Andrew
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!