how can i divide a circle into 15 equal sectors in matlab?

10 次查看(过去 30 天)
which code is for dividing a circle into 15 equal sectors?

采纳的回答

Star Strider
Star Strider 2016-4-18
编辑:Star Strider 2018-4-13
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 个评论
Eman Bany Salameh
Eman Bany Salameh 2018-4-13
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
Star Strider 2018-4-13
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.

请先登录,再进行评论。

更多回答(2 个)

Azzi Abdelmalek
Azzi Abdelmalek 2016-4-18
编辑:Azzi Abdelmalek 2016-4-18
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

Image Analyst
Image Analyst 2016-4-18
As an example, see my attached colorwheel program.

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by