Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 创建具有重叠直方图的图形并将其保存到单个文件_Linux_Matlab_Histogram_Saving Data - Fatal编程技术网

Linux 创建具有重叠直方图的图形并将其保存到单个文件

Linux 创建具有重叠直方图的图形并将其保存到单个文件,linux,matlab,histogram,saving-data,Linux,Matlab,Histogram,Saving Data,我试图编写一个Matlab脚本来分析两组特定的数据,为它们创建直方图,并将它们写入一个文件中,在这个文件中可以看到两个直方图在一个图上重叠 我创建了一个功能脚本,为1组数据创建了直方图,基本上如下所示: h1=figure; hist(data,nbins:; print(h1,'-dpng','hist.png) 然后我试着简单地添加第二行: h2=figure; 并将打印功能更改为包含h2。这显然不起作用。我发现我不能同时拥有带有打印功能的h1和h2 在搜索了互联网并寻找解决方法后,我

我试图编写一个Matlab脚本来分析两组特定的数据,为它们创建直方图,并将它们写入一个文件中,在这个文件中可以看到两个直方图在一个图上重叠

我创建了一个功能脚本,为1组数据创建了直方图,基本上如下所示:

h1=figure;
hist(data,nbins:;

print(h1,'-dpng','hist.png)
然后我试着简单地添加第二行:

h2=figure;
并将打印功能更改为包含h2。这显然不起作用。我发现我不能同时拥有带有打印功能的h1和h2

在搜索了互联网并寻找解决方法后,我决定尝试使用saveas。我得出以下结论:

h=findobj(gca,'Type','patch');
hist(data1,nbins);
hold on;
hist(data2,nbins);

set(h(1),'FaceColor','r','EdgeColor','k');
set(h(2),'FaceColor','b','EdgeColor','k');

saveas(h,'-dpng','hist.png')

但这也不太管用。我在Mathworks网站上没有找到任何可以帮助我解决这个问题的东西,在其他任何网站上也没有找到任何东西。我正在使用一台Linux计算机通过SSH连接到另一台服务器,因此我可以查看绘制的绘图的唯一方法是将它们保存到一个文件中,然后打开它们。请让我知道,如果你有任何建议,以完成我在第一段概述的任务。谢谢。

一种方法是对不同的直方图使用不同的轴。您可以为此使用子批次:

subplot(2,1,1)
hist(data1,nbins);
subplot(2,1,2)
hist(data2,nbins);
另一种方法是找到一个公共容器(
x
),并将
hist
输出返回向量。然后使用条形函数进行绘图

nbins = 20;
x = linspace(min([data1(:);data2(:)]),max([data1(:);data2(:)]),nbins);
h1 = hist(data1, x);
h2 = hist(data2, x);
hb = bar(x,[h1(:),h2(:)],'hist');

% change colors and set x limits
set(hb(1),'FaceColor','r','EdgeColor','k');
set(hb(2),'FaceColor','b','EdgeColor','k');
gap = x(2)-x(1);
xlim([x(1)-gap x(end)+gap])

一种方法是对不同的直方图使用不同的轴。您可以为此使用子批次:

subplot(2,1,1)
hist(data1,nbins);
subplot(2,1,2)
hist(data2,nbins);
另一种方法是找到一个公共容器(
x
),并将
hist
输出返回向量。然后使用条形函数进行绘图

nbins = 20;
x = linspace(min([data1(:);data2(:)]),max([data1(:);data2(:)]),nbins);
h1 = hist(data1, x);
h2 = hist(data2, x);
hb = bar(x,[h1(:),h2(:)],'hist');

% change colors and set x limits
set(hb(1),'FaceColor','r','EdgeColor','k');
set(hb(2),'FaceColor','b','EdgeColor','k');
gap = x(2)-x(1);
xlim([x(1)-gap x(end)+gap])