如何解决matlab中的散点图错误 [英] how to solve scatterplot error in matlab
问题描述
以下是我正在编写的代码的一部分,
following is a part of the code I am writing,
for ii=1:length(k31)
B = [k31(ii);k32(ii)];
X=abs( pinv(A)*B);
g1(ii)=X(1,:);
g2(ii)=X(2,:);
g3(ii)=X(3,:);
end
scatter(x(1:end-1), y(1:end-1), 5, g1);
但是我无法绘制数据,错误如下
But I am not able to plot the data, the error is as follows
??? Error using ==> scatter at 79
C must be a single color, a vector the same length as X, or an M-by-3 matrix.
x和y与k31的尺寸相同...但是仍然显示出这样的错误
x and y have the same dimensions as k31...but still it is showing such an error
推荐答案
您正在喂养 scatter
,带有4个参数:scatter(X, Y, S, C)
.您的错误状态:
You are feeding scatter
with 4 arguments: scatter(X, Y, S, C)
. Your error states:
C
必须是单色,长度与X
相同的向量或M×3矩阵.
C
must be a single color, a vector the same length asX
, or an M-by-3 matrix.
表示第四个参数g1
与第一个参数的尺寸不同.
meaning that the fourth argument g1
does not have the same dimensions as the first argument.
这里可能发生的是,您没有在循环之前重新初始化g1
,因此它保留了先前的大小.将以下行放在for
-循环之前:
What probably happened here is that you didn't re-initialize g1
before the loop, and so it retained its previous size. Put the following line before the for
-loop:
g1 = zeros(size(k31));
它应该可以工作.
这篇关于如何解决matlab中的散点图错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!