How can I plot 2 rings in 3D?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Stef
le 3 Août 2018
Réponse apportée : Star Strider
le 3 Août 2018
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 commentaires
Réponse acceptée
Star Strider
le 3 Août 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Scatter Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!