フィルターのクリア

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 Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by