[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math

Search:


View post   

>> No.8591080 [View]
File: 143 KB, 1248x1144, Screen Shot 2017-01-09 at 6.58.57 PM.png [View same] [iqdb] [saucenao] [google]
8591080

Having a bit of trouble with Matlab... Trying to draw a histogram based on the result of 10,000 dice rolls, but I have no idea what MATLAB is trying to do when it's actually drawing the graph...


Here's my code:

%Make a histogram of the result of 10_000 trials of (two dice)
%being thrown

range = 6; % rand() returns a number between 0 and one
result_array = zeros(1, 12);

num_trials = 10000;
for (i = 1:num_trials)
a_throw = floor( rand() * range + 1 );
b_throw = floor( rand() * range + 1 );

result = floor(a_throw + b_throw); %Convert to integer
result_array(result) = result_array(result) + 1; %add one to resp. entry
end
result_array %Print out resulting array
hist(unidrnd(10000, 1, 6));

Navigation
View posts[+24][+48][+96]