MATLAB: Coin toss game simulation.

simulation

I'm trying to create a simple coin toss simulation, the game is as follows.
a player flips a coin, if heads they score 1, if tails -1. the player can stop at any point and win the current score divided by the number of games.
I want to create some code that simulates this for say 10 coin tosses and outputs the scores at each toss in for example a vector and the separately outputs the larges score.
any help would be hugely appreciated.

Best Answer

num_toss = 10;
%Toss the coin
vec_toss = rand(num_toss,1) > 0.5;
%Get the average:
mean_vec = cumsum(vec_toss)./(1:num_toss);
Related Question