Hi, so I am very new at this! I am writing a code that is trying to simulate a fair coin toss that flips a coin 100x with -1 being tails and 1 being heads. I am then trying to run this 100 times and find the mean of those 100 samples and put it into a histogram.
Here is what I have written currently:
samplesize = 50;nsamples=100;coins = (binornd(1,.5,nsamples,1)*2)-1;count_toss = mean(coins);for i = 1:100mean(count_toss)endlots_toss = mean(count_toss);Bins = 10;histfit(lots_toss,10);
When I run this I get:
Error using histfit (line 94)
Not enough data in X to fit this distribution.
Error in coin_toss (line 15)
I also generate the same mean for the loop, when I am trying to generate 100 different means for the histogram.
I'm not sure what I'm missing but I think I need to change something in the loop index, but I'm not entirely sure of how to code it and have been searching how to do this-I think right now I have it hard programmed in to just display the same number repeatedly which is why I'm getting the error I'm seeing down below. If someone can help point me in the right direction on how to alter this slightly I think it should be okay? I'm fairly sure it's not THAT far off.