Script Efficiency for Plotting Spheres
Show older comments
I have some code that I found in another thread for plotting spheres in 3d cartesian space. This code works excellently, and with relative speed, if I'm plotting 1000 or fewer points. However, my data set (A, which contains x,y,z coordinates, as well as the radii of spheres, and the spheres have rigid boundaries) contains 60,000 spheres. Whether the spheres are uniform in size or not, plotting in excess of ~1000 points takes quite a long time. I'm wondering if there is a more efficient means of coding this.
Current script:
A = textread('out1404000.dump', '', 'headerlines', 9 );
xyz = A(1:1000, 4:6); %I'm currently taking rows 1:1000, but would prefer to plot all rows.
r2 = A(1:1000, 3); %I'm currently taking rows 1:1000, but would prefer to plot all rows.
[X,Y,Z] = sphere;
plotfun = @(c,r2) surf(X*r2 + c(1),Y*r2 + c(2),Z*r2 + c(3));
figure(3)
hold on
axis equal
grid on
h = cellfun(plotfun,num2cell(xyz,2),num2cell(r2),'UniformOutput',0);
Here is an example matrix containg columns, from left to right, of radius, x, y, z.
0.5000 -45.1766 -48.5664 0.4843
0.5000 -50.0416 -49.2495 0.4961
1.0000 -47.9513 -47.9333 0.9957
1.0000 -49.9313 -47.3837 1.8390
1.0000 -48.8482 -50.0006 0.9927
0.5000 -49.6122 -48.1071 0.4921
0.5000 -44.6511 -49.4200 0.4985
0.5000 -45.2021 -50.4440 0.4960
0.5000 -50.5025 -49.5157 1.3356
3.5000 -44.7595 -46.8283 4.0392
0.5000 -47.3386 -49.2080 0.4978
0.5000 -49.3041 -47.1562 0.4976
0.5000 -45.1425 -44.9833 0.4985
0.5000 -46.6837 -47.3048 0.5152
0.5000 -46.0781 -48.0926 0.4918
0.5000 -47.6858 -46.5254 0.4971
0.5000 -46.0302 -45.4569 0.4980
0.5000 -50.4889 -47.6416 0.4879
0.5000 -46.5252 -46.3235 0.4939
0.5000 -48.6297 -46.4955 0.8222
0.5000 -50.4515 -46.6441 0.4972
0.5000 -50.4994 -50.4919 0.4983
1.0000 -48.9826 -48.9605 2.6821
0.5000 -47.6021 -46.0127 1.3478
0.5000 -47.6011 -49.3150 1.4547
0.5000 -45.6905 -50.5026 1.3610
0.5000 -47.5423 -50.5057 0.4921
0.5000 -46.4702 -50.4537 0.4985
0.5000 -48.0139 -45.1044 1.3070
0.5000 -48.3227 -45.6022 0.4980
0.5000 -49.1370 -45.0227 0.4959
0.5000 -50.2749 -49.6185 2.3011
0.5000 -50.4952 -45.3492 0.4966
0.5000 -45.9672 -49.1762 0.4970
0.5000 -47.2015 -45.5727 0.4985
0.5000 -46.1117 -49.5996 1.3873
0.5000 -50.5028 -48.5089 0.9728
0.5000 -49.2593 -48.5942 1.2715
0.5000 -47.6558 -44.6532 0.4964
0.5000 -48.7230 -46.9734 4.4883
1.0000 -50.0172 -48.8540 4.3678
0.5000 -46.1410 -50.5063 4.7379
0.5000 -50.4774 -46.0237 1.2764
0.5000 -49.4659 -46.0204 0.4975
1.0000 -50.0074 -46.8401 3.7471
0.5000 -48.8859 -44.6244 1.3741
0.5000 -49.5962 -45.4225 1.2849
0.5000 -50.5010 -50.5006 1.4961
0.5000 -48.5182 -47.8545 4.9038
0.5000 -50.5004 -46.0659 2.2728
Answers (1)
darova
on 13 Mar 2020
- Try to reduce mesh
[X,Y,Z] = sphere(5);

- If you have so many sphere maybe you don't need inside part

- maybe slice function will be helpfull

Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!