How can i make a n-pointed star?

6 次查看(过去 30 天)
--------------------------------------------------------------------------------------------
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
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