How to plot solid concentric circles in a meshgrid?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Viron Gil Estrada
am 14 Mär. 2018
Beantwortet: Star Strider
am 14 Mär. 2018
I am trying to plot solid concentric circles in a meshgrid but the code I used only plots the borders of the circles.
theta = linspace(0, 2*pi, 100);
[X, Y] = meshgrid(1:1:4, theta);
a = 0;
b = 0;
plot(a+cos(Y).*X, b+sin(Y).*X);
axis equal
What I intend to do is to generate solid concentric circles and that the points inside the circles are valued as either 1 (white) or 0 (black). Below is a picture for visualization. Can anyone help me?
Thanks,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171266/image.png)
0 Kommentare
Akzeptierte Antwort
Star Strider
am 14 Mär. 2018
Try this:
theta = linspace(0, 2*pi, 100);
[X, Y] = meshgrid(1:1:4, theta);
a = 0;
b = 0;
figure(2)
plot(a+cos(Y).*X, b+sin(Y).*X);
axis([-1 1 -1 1]*6)
hold on
patch([xlim fliplr(xlim)], [min(ylim)*[1 1] max(ylim)*[1 1]], 'k')
for k1 = 4 : -1 : 1
color = [1 1 1]*(mod(k1,2)==0);
patch(a+cos(Y(:,k1)).*X(:,k1), b+sin(Y(:,k1)).*X(:,k1), color);
end
hold off
axis equal
axis tight
It creates patch objects going from the largest radius to the smallest, changing the colours with each iteration of the for loop. It colours the background black first. If you want a larger background, area, increase the multiplier (here 6) in the axis call.
Experiment to get the result you want.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!