【问题标题】:Very Basic Matlab Plot非常基本的 Matlab 绘图
【发布时间】:2016-05-23 22:49:34
【问题描述】:

所以,我想画一些像这样的点(对不起我可怜的图):

所以,我对 x 中的相应数字有一些点,我想根据它们在 Y 轴上的值来绘制它们。

我还需要将每列的平均值(Y 指数)用一条直线连接起来,比如 viz。

编辑:这意味着 X 索引为 5 的列的平均值为 5.6,10 的平均值为 4.5,等等。我想要一条曲线来连接每列的平均值。蓝线连接每列的平均值。

我写了一个失败的代码,出现以下错误:

Error using scatter (line 62)
X and Y must be vectors of the same length.

代码如下:

x = [5,10,15,20];
scatter(4, data_tab.Bitsi);
hold on
scatter(8, data_tab.Bitsa);
scatter(12, data_tab.Bitsb);
scatter(16, data_tab.Bitsc);
scatter(20, data_tab.Bitsd);

5, 10 ... 的每一列也有 4 个值。 我该怎么做? 谢谢。

【问题讨论】:

  • 这句话是什么意思? “我还想用一条直线连接每列的平均值(Y 指数)”?
  • "我写了一个失败的代码:"怎么办?提供完整的错误消息或描述问题所在,以免我们猜测。
  • 已编辑。对于错误信息,我们深表歉意。
  • @horchler 添加了数据。

标签: matlab


【解决方案1】:

这不是一个优雅的解决方案,但它会绘制你想要的东西

a = rand(1,4);
mean_a = mean(a);
b = rand(1,4);
mean_b = mean(b);
c = rand(1,4);
mean_c = mean(c);
d = rand(1,4);
mean_d = mean(d);
e = rand(1,4);
mean_e = mean(e);

means_array = [mean_a mean_b mean_c mean_d mean_e];


x = [5,10,15,20];
scatter([4 4 4 4], a);
hold on
scatter([8 8 8 8], b);
scatter([12 12 12 12], c);
scatter([16 16 16 16], d);
scatter([20 20 20 20], e);
plot([4 8 12 16 20], means_array);

您的代码的问题是您没有在 scatter 函数的 x 和 y 向量中提供相同数量的元素

【讨论】:

    猜你喜欢
    • 2016-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    相关资源
    最近更新 更多