bar plot problem

11 ビュー (過去 30 日間)
raymond
raymond 2011 年 11 月 23 日
hello i"m trying to graph a bar plot from form .1 to .9 based on this index p=.1:.1:.1 but its graphing from it seems to be plotting from about -.3 to 1.3 can someone help me please fix this
win=0 step=0 for p=.1:.1:.9
for i=1:1:100
a=3
b=3
c=3
while a>0 && b>0 && c>0
step=step+1
d=rand(1,3)
if d(1,1)<p && d(1,2)<p && d(1,3) <p
a=a+0
b=b+0
c=c+0
elseif d(1,1)>p && d(1,2) >p &&d(1,3) >p
a=a+0
b=b+0
c=c+0
elseif d(1,1)<p && d(1,3) < p
a= a -1
b= b+2
c= c-1
elseif d(1,1)>p &&d(1,3) >p
a= a -1
b= b+2
c= c-1
elseif d(1,3)<p &&d(1,2) < p
a= a +2
b= b-1
c= c-1
elseif d(1,2)>p && d(1,3) >p
a= a +2
b= b-1
c= c-1
elseif d(1,1)<p &&d(1,2) < p
a= a -1
b= b-1
c= c+2
elseif d(1,1)>p && d(1,2) >p
a= a -1
b= b-1
c= c+2
end
end
win=win+1
end
%axis([0 1 0 75])
avg=step/100
bar(p,avg)
hold on
end

採用された回答

the cyclist
the cyclist 2011 年 11 月 23 日
A quick fix is to put the following line after your bar() command:
>> set(get(gca,'Children'),'BarWidth',0.1)
The problem is that your bars are being plotted with width 0.8, by default. Then, each one overlaps the previous ones. If you put a breakpoint just after that bar() command, and see each bar being put down, you'll see what I mean.
A better solution, but which I am too lazy to implement for you, would be for you to get all the values of p and avg stored into vectors, then do the bar plot with the vectors, outside the loop. Then MATLAB would do the work of adjusting the widths appropriately.
  1 件のコメント
raymond
raymond 2011 年 11 月 23 日
thank you works great

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by