我必须在 matlab 中绘制它:
所以我写了以下代码:
x=[0.9 1 0.9 -0.9 0.7 0.7 -0.9 0.9];
y=[-1 0 1 -0.5 -0.8 0.8 -0.4 -1];
plot(x,y);
但这给了我:
这个方法不足以绘制第一个图吗...还有其他简短的方法吗...
最佳答案
您可以更好地定位数据点
nPoints = 7;
th = linspace(-2*pi, 2*pi, 2*nPoints+1);%// extra point to close the curve
r = 1;
x = r*cos(th);
y = r*sin(th);
scatter( x, y, 'ro' );
hold on;
plot( x(1:2:end), y(1:2:end), 'b-' );
axis equal;
结果:
顺便说一句,此代码适用于任何奇怪的 nPoints
- 只需尝试;)
关于matlab - 在Matlab中绘制星星形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26326385/