bar plot problem
9 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!