How can I plot 2 rings in 3D?

2 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2018-8-3
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 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by