Color histogram as a function of x-axis

1 回表示 (過去 30 日間)
Jacob
Jacob 2011 年 9 月 7 日
Hello all,
I am having trouble getting a histogram colored the way I want. I think the problem is simple, but its alluding me. All I want to do is have the plotted histogram color graded as a function of the x-axis values.
Best, -J

採用された回答

Grzegorz Knor
Grzegorz Knor 2011 年 9 月 7 日
There is no built in function in MATLAB to do this.
My suggestion is:
x = rand(1000,1);
[n,xout] = hist(x);
width = 0.8*(xout(2)-xout(1));
base = 0;
clr = jet(length(n));
hold on
for k=1:length(n)
fill([xout(k)-width/2 xout(k)+width/2 xout(k)+width/2 xout(k)-width/2],...
[base base n(k) n(k)],clr(k,:))
end
hold off
see also:
  1 件のコメント
Jacob
Jacob 2011 年 9 月 7 日
Grzegorz,
That worked brilliantly! Thank you very much.
Best,
Jacob

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

その他の回答 (0 件)

カテゴリ

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