How can I plot 2 rings in 3D?
2 views (last 30 days)
Show older comments
I want to scatter 2 rings first in 2D and then in 3D. In 2D one circle should lie within the other. In 3D one circle should lie above the other so that a separating hyperplane can be put in between. Does anybody know how to code this in matlab? Should look somehow like this: https://cdn-images-1.medium.com/max/1600/0*ngkO1BblQXnOTcmr.png
0 Comments
Accepted Answer
Star Strider
on 3 Aug 2018
Try this:
The Code —
N1 = 200; % Number Of Points In Ring
R1 = 0.25 + 0.2*(rand(1, N1)-0.5); % Random Marker Radii
A1 = linspace(0, 2*pi, N1); % Define Angle Vector
Ring1 = R1.*[cos(A1); sin(A1)]; % Create Ring Coordinates
N2 = 200;
R2 = 0.85 + 0.2*(rand(1, N1)-0.5);
A2 = linspace(0, 2*pi, N1);
Ring2 = R2.*[cos(A1); sin(A1)];
figure
plot(Ring1(1,:), Ring1(2,:), '^b', 'MarkerFaceColor','b')
hold on
plot(Ring2(1,:), Ring2(2,:), 'or', 'MarkerFaceColor','r')
hold off
axis equal
N1 = 200; % Number Of Points In Ring
R1 = 0.25 + 0.2*(rand(1, N1)-0.5); % Random Marker Radii
Z1 = 0.10 + 0.2*(rand(1, N1)-0.5); % Random Z-Values
A1 = linspace(0, 2*pi, N1); % Define Angle Vector
Ring1 = R1.*[cos(A1); sin(A1)]; % Create Ring Coordinates
N2 = 200;
R2 = 0.85 + 0.2*(rand(1, N1)-0.5);
Z2 = 0.80 + 0.2*(rand(1, N1)-0.5);
A2 = linspace(0, 2*pi, N1);
Ring2 = R2.*[cos(A1); sin(A1)];
figure
plot3(Ring1(1,:), Ring1(2,:), Z1, '^b', 'MarkerFaceColor','b')
hold on
plot3(Ring2(1,:), Ring2(2,:), Z2, 'or', 'MarkerFaceColor','r')
hold off
axis equal
grid on
You will probably need to tweak this a bit to get the result you want. See the documentation for the plot (link) and plot3 (linked to at the end of that page) functions to discover all their options.
The Plots —
0 Comments
More Answers (0)
See Also
Categories
Find more on Scatter 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!