【问题标题】:To represent the two 2-D matrices in a single bar graph plot在单个条形图中表示两个二维矩阵
【发布时间】:2017-04-11 14:36:02
【问题描述】:

我确实从我的核心流程中生成了两个二维矩阵。现在,我想通过条形图来表示它们。 我可以设法获得独立矩阵的 3d 条形图,如附图所示。

我的数据矩阵是

  1. “xData” - 大小为:(52 x 46)
  2. “yData” - 大小为:(52 x 46)

它们的大小始终相同。

现在,我想用 'Grouped Style' 将它们一起表示,如here 所示。我通过将它们(xData 和 yData)组合在一起得到 3D 维矩阵,即生成 52 x 46 x 2 矩阵,然后尝试使用 bar3 命令进行绘图;但是,我遇到了一个错误,无法绘图。 各位大侠有什么办法吗?

【问题讨论】:

  • 您能否向我们提供您用于创建显示图形的确切 Matlab 代码以及您尝试使用的代码以及确切的错误消息?

标签: matlab figure


【解决方案1】:

我设法使用循环和SO answer

% generate random data
sz = [5 4];
xData = rand(sz);
yData = rand(sz);
% plot zeros in the same size to prepare plot
Z = zeros(sz);
h0 = bar3(Z);
set(h0,'EdgeColor','none','FaceColor','none');
axis tight
% plot each data column in a loop
hold on
for kk = 1:size(xData,2)
    h1 = bar3([xData(:,kk),yData(:,kk)],'grouped');
    % move current bars to their x position
    cellfun(@(x) set(h1,'XData', x + (kk - 1)), get(h1,'XData'));
end

【讨论】:

  • 谢谢@user2999345 看起来它会做必要的..会相应地更新你
猜你喜欢
  • 2014-03-05
  • 2021-12-09
  • 1970-01-01
  • 2016-05-16
  • 2016-04-25
  • 2015-03-19
  • 2021-10-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多