arrays - MatLab Bottleneck -
i working big arrays (~6x40million) , code showing great bottlenecks. experienced programming in matlab, don't know inner processes (like memory , such...).
my code looks follows(just essentials, of course variables initialized, specially arrays in loops, don't want bomb code ):
first read file,
disp('point cloud import , subsampling') tic fid=fopen(strcat(name,'.dat')); c=textscan(fid, '%d%d%f%f%f%d'); %<= big! fclose(fid);
then create arrays out of contents,
y=c{1}(1:subsampling:end)/subsampling; x=c{2}(1:subsampling:end)/subsampling; %... , on other rows clear c %no 1 wants 400+ millon doubles lying around.
and clear cell array (1), , create images , arrays new values
for i=1:length(x) pcimage(y(i)+subsize(1)-maxy+1,x(i)+1-minx)=reflectanse(i); pixelcoordinates(y(i)+subsize(1)-maxy+1,x(i)+1-minx,:)=coordinates(i,:); end toc
everything runs more or less smoothly until here, manipulate arrays
disp('overlap alignment') tic pcimage=pcimage(:,[1:maxx/2-overlap,maxx/2:end-overlap]); %-30 overlap? pixelcoordinates=pixelcoordinates(:,[1:maxx/2-overlap,maxx/2:end-overlap],:); sphere=sphere(:,[1:maxx/2-overlap,maxx/2:end-overlap],:); toc
and big bottleneck, gets worst @ next step
disp('planar view , point cloud matching') tic compimage=zeros(max(subsize(1),pcsize(1)),max(subsize(2),pcsize(2)),3); compimage(1:subsize(1),1:subsize(2),2)=subimage; %exportimage cyan compimage(1:subsize(1),1:subsize(2),3)=subimage; compimage(1:pcsize(1),1:pcsize(2),1)=pcimage; %pointcloudimage red toc
output
point cloud import , subsampling
elapsed time 181.157182 seconds.
overlap alignment
elapsed time 408.750932 seconds.
planar view , point cloud matching
elapsed time 719.383807 seconds.
my questions are: clearing unused objects c
in 1 have effect? (it doesn't seem that)
am overseeing other important mechanisms or rules of thumb, or whole thing , supposed happen this?
when subsref
used, matlab makes copy of sub referenced elements. may costly large arrays. faster catenate vectors like
res = [a,b,c];
this not possible current code written above, if code modified make work, may save time.
edit multi-dimensional arrays need use cat
compimage = cat(dim,subimage,subimage,pcimage);
where dim
3 example.
Comments
Post a Comment