Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
如果我有
matrix= 0.0494 2.3691 -0.0973 0.8026 -0.3040 -0.0861 -0.0626 2.5688 -0.4144 0.7054 0.0633 -0.0991 -0.8386 -1.2229 1.8929 2.6260 1.7687 2.3963 1.8243 -0.5543 1.9272 -0.3946 -0.0682 1.7404 -0.1180 2.2323 0.4071 -0.1878 0.6406 2.5602 -0.2144 2.0014 0.1091 -0.1874 -0.1102 0.2922 您如何以一种颜色绘制一列,而以另一种颜色绘制另一列,或者以一种颜色绘制其中的一些列 scatter(matrix(:,1),matrix(:,2), 'b','+'); 回答: scatter不会单独绘制每列。这是第column 1 column 2与第column 2 。因此,散点图上的每个点都由两列组成。换句话说, scatter(x,y)和plot(x,y,'o')之间没有区别。但是, scatter还有其他功能,这就是为什么scatter可以用作其他功能的原因。如果您只是想用两种颜色分别绘制每列,则可以简单地执行plot(matrix,'o')而MATLAB应该自动为第一列分配蓝色,为第二列分配绿色。 scatter也将色图作为参数。因此,如果您打算绘制一种颜色的数据(两列)的一半,而另一种颜色,则可以尝试这样做 nRows=size(matrix,1); red=repmat([1,0,0],fix(nRows/2),1);%# use fix so that you don't get an error if nRows is not even. green=repmat([0,1,0],nRows-fix(nRows/2),1); scatter(matrix(:,1),matrix(:,2),[],[red;green]); 更多&回答... |
![]() |
![]() |