Hello all, I am using this code for getting the data point coordinates among defined vertices .
ver = vertice; % nX3 matrix
ver=ceil(ver);
tess=delaunay(ver);
mn_x=min(ver(:,1));
mx_x=max(ver(:,1));
mn_y=min(ver(:,2));
mx_y=max(ver(:,2));
mn_z=min(ver(:,3));
mx_z=max(ver(:,3));
[X,Y,Z]=ndgrid(mn_x:0.8:mx_x , mn_y:0.8:mx_y , mn_z:0.8:mx_z);
sz=size(X);
P=ones(sz(1)*sz(2)*sz(3),3);
for i=1:sz(1)*sz(2)*sz(3)
P(i,1)=X(i);
P(i,2)=Y(i);
P(i,3)=Z(i);
end
pts=zeros(size(P));
for j=1:length(P)
t=tsearchn(ver,tess,P(j,:));
isin=~isnan(t);
if isin ==1
pts(j,:)=P(j,:);
end
end
It works fine but takes a lot time to calculate. How to improve the performance of code ? Thank you :)

댓글 수: 4

Geoff Hayes
Geoff Hayes 2016년 2월 28일
yogesh - please quantify what you mean by it takes a lot of time. What are the dimensions of vertice? Is delaunay a function built-in to MATLAB (see http://www.mathworks.com/help/matlab/ref/delaunay.html) or something that you have written?
yogesh jain
yogesh jain 2016년 2월 29일
편집: yogesh jain 2016년 2월 29일
Hello mr. Geoff , 1. Takes a lot time straightly tells that the computation time is more, it should be minimized . 2. 'n' here is no. of vertices , could be more . 3. Absolutely delaunay is inbuilt function of MATLAB, which creates a 2-D or 3-D Delaunay triangulation of the points.
Thank you :)
Jan
Jan 2016년 2월 29일
@yogesh jain: It matters if you are talking about day or micro-seconds. n might be 1e3 or 1e10, so please be specific and do not let us guess the details.
yogesh jain
yogesh jain 2016년 2월 29일
for the value of n=about 100 , it takes 50-55 seconds .

댓글을 달려면 로그인하십시오.

 채택된 답변

Jan
Jan 2016년 2월 29일

0 개 추천

Please use the profile to find the bottleneck of the code. Some parts are easy to accelerate, but this does not really help, if they take 1% of the total time. E.g.:
P=ones(sz(1)*sz(2)*sz(3),3);
for i=1:sz(1)*sz(2)*sz(3)
P(i,1)=X(i);
P(i,2)=Y(i);
P(i,3)=Z(i);
end
Faster:
P = [X(:), Y(:), Z(:)];

댓글 수: 4

Thanks but the part of the code which cosumes most of the time is -
pts=zeros(size(P));
for j=1:length(P)
t=tsearchn(ver,tess,P(j,:));
isin=~isnan(t);
if isin ==1
pts(j,:)=P(j,:);
end
end
This should be improved . thank you
Jan
Jan 2016년 2월 29일
And is the main part of the time spent inside tsearchn? Do I see it correctly that inside this function the convex hull is obatined in each iteration? Did you try to call it once with the matrix P?
yogesh jain
yogesh jain 2016년 2월 29일
Yes Mr. Jan "tsearchn" consumes the most time and it is obtaining convexhull in each iteration. thank you
Steven Lord
Steven Lord 2016년 2월 29일
As Jan suggested, rather than calling TSEARCHN multiple times with one row at a time call it with a matrix as the third input and perform all your searches at once. Then check which of the points are outside the convex hull and which are inside and process each group appropriately.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mapping Toolbox에 대해 자세히 알아보기

질문:

2016년 2월 26일

댓글:

2016년 2월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by