bar plot problem
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
the cyclist
el 23 de Nov. de 2011
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Bar Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!