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

9 ビュー (過去 30 日間)
meihua
meihua 2013 年 11 月 8 日
コメント済み: Image Analyst 2013 年 11 月 16 日
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 件のコメント
Image Analyst
Image Analyst 2013 年 11 月 16 日
You forgot to attach the figures or screenshots.

サインインしてコメントする。

回答 (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.

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by