필터 지우기
필터 지우기

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

조회 수: 10 (최근 30일)
akanksha dubey
akanksha dubey 2016년 4월 18일
댓글: Star Strider 2018년 4월 13일
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