How can i make a n-pointed star?

조회 수: 3 (최근 30일)
Joungyoung
Joungyoung 2014년 12월 8일
편집: Giorgos Papakonstantinou 2014년 12월 9일
--------------------------------------------------------------------------------------------
clear all; close all; clc;
N = input('natural number 1~100 : ');
m = ceil(sqrt(length(N)));
n = ceil(sqrt(length(N)));
figure('number','off'); hold on
for c = 1 : length(N) ;
if rem(N(1,c),2)==1 %odd number
t = 0:N:N(1,c)*N(1,c);
x = cos((N(1,c)-1)/N(1,c)*pi*t);
y = sin((N(1,c)-1)/N(1,c)*pi*t);
else %even number(Now, even number code = odd number code)
t = 0:N.*N:N(1,c)*N(1,c);
x = cos((N(1,c)-1)/N(1,c)*pi*t);
y = sin((N(1,c)-1)/N(1,c)*pi*t);
end
subplot(m,n,c); hold on
plot(x,y)
hold off
end
hold off
---------------------------------------------------------------------------------------------
I'm student of korea ,which learning MATLAB
I input vector 1:9, this figure out.
if I input odd number, maked n-pointed star. but I input even number, maked 2n-pointed star.
How can I n-pointed star???? please

답변 (1개)

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2014년 12월 9일
편집: Giorgos Papakonstantinou 2014년 12월 9일
Hello student from Korea!
Why don't you try this?
q = 4; % connect every qth point out of p points
mingon = 2*q + 1;
maxgon = mingon + 11;
jj = 0;
for ngon = mingon:maxgon;
theta = linspace(0, 2*pi, ngon+1);
[xx, yy] = pol2cart(theta, 1);
K = diag(ones(q,1), ngon-q)+diag(ones(ngon-q,1), q)+diag(ones(q,1), -ngon+q)+diag(ones(ngon-q,1), -q); % adjacency matrix
jj = jj + 1;
subplot(3, 4, jj)
gplot(K, [xx' yy'])
hold all
plot(xx, yy)
axis equal
title(['\{' num2str(ngon, '%d') '/' num2str(q, '%d') '\}'])
end

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by