필터 지우기
필터 지우기

Using Logical Indexing with Matrices

조회 수: 1 (최근 30일)
Andrew
Andrew 2014년 2월 6일
편집: Matt J 2014년 2월 6일
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

채택된 답변

Matt J
Matt J 2014년 2월 6일
편집: Matt J 2014년 2월 6일
tmp=ns*X-planeloc*norm(ns)^2;
X2=X(:,abs(tmp)<.0001);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by