how can i divide a circle into 15 equal sectors in matlab?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
akanksha dubey
el 18 de Abr. de 2016
Comentada: Star Strider
el 13 de Abr. de 2018
which code is for dividing a circle into 15 equal sectors?
0 comentarios
Respuesta aceptada
Star Strider
el 18 de Abr. de 2016
Editada: Star Strider
el 13 de Abr. de 2018
This works:
a = linspace(0, 2*pi, 150);
r = 1;
x = r*cos(a);
y = r*sin(a);
figure(1)
plot(x, y)
hold on
plot([zeros(1,15); x(1:10:end)], [zeros(1,15); y(1:10:end)])
hold off
axis equal
EDIT — (13 Apr 2018 at 19:45 UCT)
To scale it automatically for any desired number of segments, use this code:
N = 15; % Number Of Segments
a = linspace(0, 2*pi, N*10);
r = 1;
x = r*cos(a);
y = r*sin(a);
figure(1)
plot(x, y)
hold on
plot([zeros(1,N); x(1:10:end)], [zeros(1,N); y(1:10:end)])
hold off
axis equal
2 comentarios
Eman Bany Salameh
el 13 de Abr. de 2018
I want to decrease the number of sectors to be 8. I tried to change the number in this statment
% plot([zeros(1,15); x(1:10:end)], [zeros(1,15); y(1:10:end)])
but I got this error
% Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in sectors (line 8)
plot([zeros(1,8); x(1:10:end)], [zeros(1,8); y(1:10:end)])
Could you please tell me what this do?
% [zeros(1,8); x(1:10:end)], [zeros(1,8); y(1:10:end)]
Star Strider
el 13 de Abr. de 2018
You also have to change ‘a’ to be 10 times the number of segments, so:
a = linspace(0, 2*pi, 80);
for 8 segments.
I tweaked my earlier code to be robust to any number of segments, and added it as an edit. You may want to use it instead.
Más respuestas (2)
Azzi Abdelmalek
el 18 de Abr. de 2016
Editada: Azzi Abdelmalek
el 18 de Abr. de 2016
alpha=-pi:0.01:pi;
n_sect=7
sect=2*pi/n_sect
clr='bgrycmk';
for k=1:n_sect
a0=-pi+(k-1)*sect
a1=-pi+k*sect
t=a0:0.01:a1
x=cos(t)
y=sin(t)
fill([ 0 x],[0 y],clr(k))
hold on
end
axis equal
0 comentarios
Image Analyst
el 18 de Abr. de 2016
As an example, see my attached colorwheel program.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174122/image.jpeg)
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!