问题
I want to make two bars in the same fig in matlab. Now, I have two separate bar charts, what I want to do is combining them in one chart but with different colors (eg red and blue) to differentiate between the two barcharts. This is the two barcharts appearing:

what I want to do is something like this:
Below is the code I'm using so if anyone could please help me.
load('x640_Sensor_Lights_On_1000mm-pgms.mat');
uu=unique(n);
nn=histc(n, uu);
h=figure; bar(uu,nn/numel(n));
print(h, '-dpdf', 'x1000');
saveas(h,'x1000','fig');
load('k640_Sensor_Lights_On_1000mm-pgms.mat');
uu=unique(n);
nn=histc(n, uu);
h=figure; bar(uu,nn/numel(n));
print(h, '-dpdf', 'k1000');
saveas(h,'k1000','fig');
回答1:
You can check out the examples in bar() and specifically about bar styles:
回答2:
Try inserting the line "hold on" before your code for the second bar graph and "hold off" after.
> load('x640_Sensor_Lights_On_1000mm-pgms.mat');
uu=unique(n);
nn=histc(n, uu);
h=figure; bar(uu,nn/numel(n));
print(h, '-dpdf', 'x1000');
saveas(h,'x1000','fig');
load('k640_Sensor_Lights_On_1000mm-pgms.mat');
uu=unique(n);
hold on;
nn=histc(n, uu);
h=figure; bar(uu,nn/numel(n));
print(h, '-dpdf', 'k1000');
saveas(h,'k1000','fig');
hold off;
来源:https://stackoverflow.com/questions/16312749/how-to-make-two-bars-in-the-same-fig-matlab