how to generate random two concentric spheres synthetic data?
3 views (last 30 days)
Show older comments
mohammad ghr
on 11 May 2015
Commented: mohammad ghr
on 11 May 2015
How to generate random two concentric spheres synthetic data with radius1=40 and radius2 =100 in MATLAB and save that data in format *.mat with one variable.(1000*3 double)? Also, how to plot this data in 3D with 2 colors: red and blue?
rng(0,'twister');
rvals = 2*rand(1000,1)-1;
elevation = asin(rvals);
azimuth = 2*pi*rand(1000,1);
radii = 3*(rand(1000,1).^(1/3));
[x,y,z] = sph2cart(azimuth,elevation,radii);
data=[x,y,z];
figure
plot3(x,y,z,'.');
axis equal
The output should look like this photo.
0 Comments
Accepted Answer
Walter Roberson
on 11 May 2015
rng(0,'twister');
rvals = 2*rand(500,2)-1;
elevation = asin(rvals);
azimuth = 2*pi*rand(500,2);
radii = 3*(rand(500,2).^(1/3));
[x,y,z] = sph2cart(azimuth,elevation,radii);
allxyz = [x(:,1)*radius1, y(:,1)*radius1, z(:,1)*radius1;
x(:,2)*radius2, y(:,2)*radius2, z(:,2)*radius2];
Now save allxyz: it is your requested one variable.(1000*3 double)
To plot,
figure
plot3(allxyz(1:end/2,1),allxyz(1:end/2,2),allxyz(1:end/2,3),'r.');
hold on
plot3(allxyz(end/2+1:end,1),allxyz(end/2+1:end,2),allxyz(end/2+1:end,3),'b.');
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices 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!