【问题标题】:Matlab subplot function not workingMatlab子图功能不起作用
【发布时间】:2017-06-30 17:48:24
【问题描述】:

我一直在尝试在 Matlab 中使用 subplot 函数,使用以下代码:

x = 0:10;
figure
subplot(2,2,1); plot(x,data_matrix(1,:))
subplot(2,2,2); plot(x,data_matrix(2,:))
subplot(2,2,3); plot(x,data_matrix(3,:))
subplot(2,2,4); plot(x,data_matrix(4,:))

但是,当我运行这个简单的代码时,唯一显示的是一个带有最后一个数据向量图的图形,data_matrix(4,:)。没有错误出现。相反,根本没有生成子图。是我做错了什么,还是我的编程环境存在潜在的错误导致我无法显示子图?

【问题讨论】:

  • 清除所有内容,并注释掉“figure”。这有帮助吗?
  • 不,我仍然得到相同的结果。
  • 转置矩阵喜欢data_matrix(1,:).'
  • 我刚试过了,还是不行。
  • 重启matlab?

标签: matlab plot subplot


【解决方案1】:

您确定data_matrix(1,:) 包含您期望的内容吗?你可能想检查一下。此外,如果您提供能够重现您的问题的最少代码段,那就太好了。提供的部分不会重现问题,因为您没有提供对 data_matrix 矩阵的访问权限,我怀疑这是导致问题的原因,因为运行这段代码

x=0:10;
data_matrix=rand(4,11);

figure
subplot(2,2,1); plot(x,data_matrix(1,:))
subplot(2,2,2); plot(x,data_matrix(2,:))
subplot(2,2,3); plot(x,data_matrix(3,:))
subplot(2,2,4); plot(x,data_matrix(4,:))

完美运行,如下所示(我使用 rand 重新创建了一个格式良好的 data_matrix 矩阵)

【讨论】:

  • data_matrix 只是一个包含小数的 4 x 11 矩阵。我已经检查了数据以确保它没有任何问题。
  • 当我使用随机创建的data_matrix 运行您提供的代码时,我仍然遇到同样的问题。只显示一个图。
  • 您使用的是哪个版本的matlab?在 matlab 提示符下运行 ver
  • 我正在运行以下版本的 Matlab:8.5.0.197613 (R2015a)
  • 嗯,这是一个现代版本,所以应该没有任何问题。而不是subplot(m,n,p) 尝试subplot mnp 并再次运行您的代码。
猜你喜欢
  • 2016-01-22
  • 2014-10-24
  • 2012-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-12
  • 2013-04-24
相关资源
最近更新 更多