Concentric circles with different colors

조회 수: 9 (최근 30일)
Siddhartha
Siddhartha 2018년 2월 13일
답변: Pratibha Gangwar 2022년 1월 24일
I'm trying to make concentric circles that have different edge colors like this:
I have made the concentric circles but I only can do it with one unified edge colors for all the circles. How do I specify each one with a different color?
Here is my code so far:
for
i=30:-5:5
rectangle('Position',[-i,-i,2*i,2*i],'Curvature',[1 1],...
'EdgeColor','y', 'LineWidth',4)
end
Thanks!

답변 (3개)

Gayatri Menon
Gayatri Menon 2018년 2월 16일
Hi,
Instead of using color option for specifying the color, you could use RGB triplets to specify them.You could use rand command to generate random values for RGB triplets in each iteration
rectangle('Position',[-i,-i,2*i,2*i],'Curvature',[1 1],'EdgeColor',rand(1,3), 'LineWidth',4)
Hope the above helps
Thanks

Jos (10584)
Jos (10584) 2018년 2월 16일
You can specify a colormap beforehand:
R = 30:-5:5 ; % radii
N = numel(R) ; %
Cmap = parula(N) ; % one of the many available maps, see the help
% now loop over the radii and colormaps using indexing
for k = 1:N
pos = R(k) * [-1 -1 2 2] ; % position
clr = Cmap(k,:) ; % RGB triplet
rectangle('Position', pos, 'Curvature', [1 1], ...
'EdgeColor',clr, 'LineWidth', 4)
end

Pratibha Gangwar
Pratibha Gangwar 2022년 1월 24일
5 concentric circle

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by