Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: performance issue....
Replies: 4   Last Post: Jan 18, 2013 4:39 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Curious

Posts: 1,992
Registered: 12/6/04
Re: performance issue....
Posted: Jan 18, 2013 1:01 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Philipp " <metamurk@googlemail.com> wrote in message <kdbur8$ohi$1@newscl01ah.mathworks.com>...
> Hallo together...
> I have some performance problems with my code; I've read of vectorizisation, jit or mex files - but I don't know exctly what to do and how to spped uop this thing.
> I'm tring to find planes within a point cloud - therefore I calculated normals, sorted the points due to normal direction and then I want to region grow in this similar-direction point sets to get rid of outliners. And this last part of the algorithm is very slow:
>
> function [regionSet] = growOneRegion(index,range,points)
>
> %I build a kd-tree for the points
> tree = kd_buildtree(points,0);
>
> %set a initial seed index
> openPoints = [];
> openPoints(1,1) = index;
>
> regionSet = [];
> while(~isempty(openPoints))
>
> element = openPoints(1,1);
> openPoints(1,:) = [];
> thePoint = points(element,:);
>
> %ssearch for neighbours
> try
> [index_vals,dist_vals,vector_vals] = kd_rangequery(tree,thePoint,range);
> catch exception
> index_vals = [];
> end
>
> for j=1:size(index_vals,1)
>
> idx = index_vals(j,1);
> [R,C] = find(openPoints==idx);
> [R1,C1] = find(regionSet==idx);
>
> %add them to the queue
> if(isempty(R) && isempty(R1))
> openPoints = [openPoints;idx];
> end
> end
>
> regionSet = [regionSet;element];
> regionSet = unique(regionSet);
>
> sizer = size(regionSet,1);
> sizeA = size(openPoints,1);
> disp('region sets');
> disp(sizer);
>
> disp('open points');
> disp(sizeA);
> end
>
> Hope anybody can help me...
> Best regards


Just after a quick glance, I have a couple of comments.

Statements like:
> openPoints = [openPoints;idx];
> regionSet = [regionSet;element];

that dynamically grow vectors (or matracies or arrays) are going to slow your code down considerably. Try pre-allocating them, if possible. Search this newsgroup, the Mathworks site, or the MATLAB FAQ at:
<<http://matlab.wikia.com/wiki/FAQ>>
for ways to do this.

Unless OpenPoints is a persistent variable, I'm not sure why it is necessary to follow:
> openPoints = [];
with
> openPoints(1,1) = index;





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.