matlab - 在Matlab中绘制星星形状

标签 matlab matlab-figure

我必须在 matlab 中绘制它:
enter image description here

所以我写了以下代码:

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);  

但这给了我:enter image description here

这个方法不足以绘制第一个图吗...还有其他简短的方法吗...

最佳答案

您可以更好地定位数据点

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;

结果:
enter image description here

顺便说一句,此代码适用于任何奇怪的 nPoints - 只需尝试;)

关于matlab - 在Matlab中绘制星星形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26326385/

相关文章:

matlab - 来自非元胞数组对象的元胞内容引用

Matlab oop - 如何检查两个对象是否相等

c - 我们如何将结构从 C 代码传递到 Matlab 代码

matlab - plotyy改变颜色

matlab - 将 MATLAB 图导出为 .eps 时出现字体问题

Matlab std 在 REPL 中有效,但在程序中无效

matlab - Fortran 90 中 do while 和 do while 之间的区别

matlab - 在Matlab中使用meshz命令

matlab - 在直方图/条形图中绘制两个分类数组?

matlab - 如何更改 `plotroc` 的图例中的类名?