필터 지우기
필터 지우기

How to create concentric circles?

조회 수: 8 (최근 30일)
Yro
Yro 2021년 6월 14일
댓글: Star Strider 2021년 6월 15일
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,:).
.
  댓글 수: 2
Yro
Yro 2021년 6월 15일
Great, it works. Thank you very much for your help.
Star Strider
Star Strider 2021년 6월 15일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (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