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?
0 个评论
采纳的回答
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
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
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
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!