can someone please help me figure out a issue im having plotting the results of a simulation i ran. what im trying to do is use a histogram to plot my data but when i try that i get no results on screen and the axis are all wrong however when i use use plot i get the points on screen altough barely visible without a line connecting them can someone please tell me how to fix my histogram problem or tell me how to get a line to fit my data points when i use plot
here's a plot and hist version of my code
%plot version
win=0step=0for p=.1:.1:.9for 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 5 0 75 ])
avg=step/100 plot(p,avg) hold on end disp avg %histogram version
win=0step=0for p=.1:.1:.9for 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 5 0 75 ]) avg=step/100 hist(avg,p) hold on end disp avg
Best Answer