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

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?

답변 (1개)

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

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

질문:

2013년 11월 8일

댓글:

2013년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by