How to create concentric circles?

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

采纳的回答

Star Strider
Star Strider 2021-6-15
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]
radius_array = 1×6
0.3355 0.3500 0.3540 0.3550 0.4550 0.4580
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,:).
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by