How can I plot 2 rings in 3D?

조회 수: 4 (최근 30일)
Stef
Stef 2018년 8월 3일
답변: Star Strider 2018년 8월 3일
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