【问题标题】:Matlab Bar Graph containing 2 bars包含 2 个条形的 Matlab 条形图
【发布时间】:2022-10-08 03:51:55
【问题描述】:

我正在尝试制作包含 2 个酒吧的酒吧。下面是从 excel 文件制作单个条形图的代码。但是,我知道如何制作包含 2 个条形的条形图。我需要从 2 个 excel 文件中获取数据。 1 是位置 vs NO2,另一个是位置 vs SO2。位置相同,但我需要比较 NO2 和 SO2。谁能帮我吗?

Airpollution = readtable ('Location vs No2.xlsx');
x = categorical(Airpollution{:,1});
y = Airpollution{:,2};
bar(x,y)
xlabel('Location');
ylabel('Concentration of No2');
title('Location vs Max concentration of No2');

【问题讨论】:

  • bar 的文档有很多示例。你看过那里吗? mathworks.com/help/matlab/ref/bar.html
  • 我不确定这是否可行,因为我无权访问您的数据。但既然你说你想要 2 个酒吧,我猜是 bar1=Airpollution{:,1} 和 bar2=Airpollution{:,2} 所以你需要将它们组合为你的 x (但在不同的行中): x = [Airpollution{:,1}';Airpollution{:,2}'] 现在尝试绘制 bar(x)

标签: matlab matlab-figure


【解决方案1】:

我想我知道如何......几天前我在谷歌的某个地方找到了这个:

figure(1);
[dummy, t] = hist([one;two], numBin);
nx = hist(one, t); % Sort x into bins.
nx = transpose(nx/sum(nx));
ny = hist(two, t); % Sort y into bins.
ny = transpose(ny/sum(ny));
bar(t, [nx, ny]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-12
    • 2019-11-28
    • 2017-10-24
    • 2011-09-18
    • 1970-01-01
    • 1970-01-01
    • 2023-01-08
    • 1970-01-01
    相关资源
    最近更新 更多