How to create concentric circles?
15 views (last 30 days)
Show older comments
Hello, I want to generate a series of concentric circles by filling each ring with a different color. The result I want to obtain is similar to the figure. With the code I present, I get the figure 2. How could I assign a color to each ring between the circles?
Thanks in advance
clear;
clc;
close all
x_center = 0;
y_center = 0;
pellet = 0.3355;
gap = 0.350;
w14re = 0.354;
re = 0.355;
clad = 0.455;
sicfib = 0.458;
radius_array = [pellet gap w14re re clad sicfib];
for i = 1:5
radius = 5;
theta = 0:pi/50:2*pi;
x_circle_1 = radius_array(i) * cos(theta) + x_center;
y_circle_1 = radius_array(i) * sin(theta) + y_center;
x_circle_2 = radius_array(i+1) * cos(theta) + x_center;
y_circle_2 = radius_array(i+1) * sin(theta) + y_center;
fig1 = plot(x_circle_1, y_circle_1, 'k-', 'LineWidth', 0.5);
hold on
fig2 = plot(x_circle_2, y_circle_2, 'k-', 'LineWidth', 0.5);
hold on
axis equal
axis off
end
0 Comments
Accepted Answer
Star Strider
on 15 Jun 2021
x_center = 0;
y_center = 0;
pellet = 0.3355;
gap = 0.350;
w14re = 0.354;
re = 0.355;
clad = 0.455;
sicfib = 0.458;
radius_array = [pellet gap w14re re clad sicfib]
cm = turbo(numel(radius_array)); % Choose The Appropriate 'colormap'
for i = 1:5
radius = 5;
theta = 0:pi/50:2*pi;
x_circle_1 = radius_array(i) * cos(theta) + x_center;
y_circle_1 = radius_array(i) * sin(theta) + y_center;
x_circle_2 = radius_array(i+1) * cos(theta) + x_center;
y_circle_2 = radius_array(i+1) * sin(theta) + y_center;
fig1 = plot(x_circle_1, y_circle_1, 'k-', 'LineWidth', 0.5);
hold on
fig2 = plot(x_circle_2, y_circle_2, 'k-', 'LineWidth', 0.5);
patch([x_circle_1, fliplr(x_circle_2)], [y_circle_1, fliplr(y_circle_2)],cm(i,:), 'EdgeColor',cm(i,:))
hold on
axis equal
axis off
end
Note —
In the patch call, the EdgeColor is the color of the patch it encloses. To eliminate the edge colours instead, specify 'none' instead of cm(i,:).
.
2 Comments
More Answers (0)
See Also
Categories
Find more on Polygons 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!