# How can i make a n-pointed star?

16 views (last 30 days)
Joungyoung on 8 Dec 2014 --------------------------------------------------------------------------------------------
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

Giorgos Papakonstantinou on 9 Dec 2014
Edited: Giorgos Papakonstantinou on 9 Dec 2014
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
Image Analyst on 9 Dec 2014
Wow. Pretty cool. ### Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!