Bar plot with multidimensional matrix-->columns of different color

1 view (last 30 days)
trial_type={'apples' 'oranges' 'banana' 'pears'};
for choice=1:4
trial_type_current = trial_type{1,choice};
Collecta=rand(10,8);
Collectb=rand(10,8);
figure(1)
subplot(2,2,choice)
hist(Collecta,10);
title(sprintf('%s',trial_type_current))
xlabel('peak location')
ylabel('frequency')
legend('s2', 'ppc' ,'lick', 'm1', 'med' ,'v1', 's1' ,'LL')
figure(2)
subplot(2,2,choice)
[n,x]=hist(Collectb,5);
for a=1:8
m=n(:,a);
bar(x,m/sum(m),'hist');hold on;
end
title(sprintf('%s',trial_type_current))
xlabel('peak amplitude')
ylabel('percentage')
legend('s2', 'ppc' ,'lick', 'm1', 'med' ,'v1', 's1' ,'LL')
end
I need to display my fig 2 histogram with the y-axis in percentages instead of frequency; I attempted to do this by using [n,x]=hist() and bar() but size(n)=5,8 and size(x)=5,1. So I used a for loop to cycle through each column one by one. The resulting figure plot, however, has the columns displayed in the same color, and overlapping each other. I would like it to look like the fig 1 histogram.
Additionally, I need to make error bars (mean +/- std) for the fig 2 histogram as well. How am I supposed to create an error matrix from the mean and std of my data, when the bar() uses values derived from hist() and it's bar() that I'm basing errorbar() off of?

Answers (1)

meihua
meihua on 15 Nov 2013
[n,x]=hist(Collectb,5);
for a=1:8
mn(:,a)=n(:,a)/sum(n(:,a));
end
bar(x,mn,'hist');
Fixed it.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!