# MATLAB: How to speed up surf plot for thousands of objects

3d surf parallel computing

I want to plot thousands of objects in 3d using surf plot. My code looks like this
``    % src is an m x 3 matrix. Each row is the x, y and z coordinate of an object.    [sx, sy, sz] = sphere;    for ii = 1 : length(src)        surf(sx+src(ii,1), sy+src(ii,2), sz+src(ii,3))    end``
There are up to 3000 objects that I want to plot and it takes roughly 30 secs to render. I'm wondering if there is any way to speed this up? I tried very naively with parfor, which ended up with nothing at all. I'm also wondering why parfor won't work?

``    sphere_sizes = [10 15 20 30];    object_counts = [30, 55, 100, 177, 300, 550, 1000, 1771, 3000];    results = zeros(length(sphere_sizes),length(object_counts));    for i1=1:length(sphere_sizes)        npts = sphere_sizes(i1);        for i2=1:length(object_counts)            nobj=object_counts(i2);            cla reset            drawnow            src = randn(nobj,3);            [sx,sy,sz] = sphere(npts);            tic            for ii=1:nobj                surface(sx+src(ii,1),sy+src(ii,2),sz+src(ii,3), ...                     'EdgeColor','none','FaceColor',rand(1,3))            end            drawnow            dt = toc;            results(i1,i2) = dt;            disp([num2str(dt), ' for ', num2str(nobj), ' pts'])        end    end    cla reset    hold on    for i1=1:size(results,1)        plot(object_counts,results(i1,:), ...             'DisplayName',[num2str(sphere_sizes(i1)), ' points']);    end    legend('show','Location','NorthWest');    set(gca,'YScale','log')``