以不同颜色呈现直方图 - matlab

ari*_*iel 3 statistics matlab histogram

我试图呈现两个直方图,我希望它们中的每一个都有不同的颜色.让我们说一个红色和一个蓝色.到目前为止,我把改变了两者的颜色,但只改为相同的颜色.
这是代码

close all  
b=-10:1:10;
x=randn(10^5,1);  
x=(x+5)*3;  
y=randn(1,10^5);  
y=(y+2)*3;  
hist(x,100)  
hold on   
hist(y,100);  

h = findobj(gca,'Type','patch');   
set(h,'FaceColor','r','EdgeColor','w')  
%the last two lines changes the color of both hists.
Run Code Online (Sandbox Code Playgroud)

Amr*_*mro 7

h你的代码包含手柄两个补丁的对象.尝试分别为每个分配颜色:

%# ...
h = findobj(gca, 'Type','patch');
set(h(1), 'FaceColor','r', 'EdgeColor','w')
set(h(2), 'FaceColor','b', 'EdgeColor','w')
Run Code Online (Sandbox Code Playgroud)