如何解决matlab中的散点图错误 [英] how to solve scatterplot error in matlab

查看:209
本文介绍了如何解决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 as X, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆