5x4 colored circle in a grid format

Hello,
How do I create a 5x4 circles in a grid formate with specific circles having different colors

Answers (1)

th = linspace(0,2*pi) ;
r = 0.1 ;
xc = r*cos(th) ;
yc = r*sin(th) ;
x = 1:5 ;
y = 1:4 ;
[X,Y] = meshgrid(x,y) ;
figure
hold on
for i = 1:4
for j = 1:5
patch(X(i,j)+xc,Y(i,j)+yc,rand(1,3))
end
end
Or
th = linspace(0,2*pi) ;
r = 0.1 ;
xc = r*cos(th) ;
yc = r*sin(th) ;
x = 1:5 ;
y = 1:4 ;
[X,Y] = meshgrid(x,y) ;
c = sqrt(X.^2+Y.^2) ;
scatter(X(:),Y(:),100,c(:),'filled')

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 7 Jul 2021

Answered:

on 7 Jul 2021

Community Treasure Hunt

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

Start Hunting!