matrix for simulating 20 coin tosses

2 visualizaciones (últimos 30 días)
Levan Tavdgiridze
Levan Tavdgiridze el 6 de Dic. de 2020
Comentada: Ameer Hamza el 6 de Dic. de 2020
Hello,
I am trying to create 20X1000 matrix which simulates 20 coin tosses 1000 times. So matrix is binary. then I would like create 20 number vector for counting ones in matrix. for example if number of ones in first row is 15, fifteenth number in vector will be increased by one. and I would like to show this vector as a graph so it shows how many rows had how many ones in it.

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 6 de Dic. de 2020
Editada: Ameer Hamza el 6 de Dic. de 2020
Try this
M = randi([0 1], 20, 1000);
M_sum = sum(M);
freq = accumarray(M_sum(:), 1, [20 1]);
bar(1:20, freq)
xlabel('Number of ones');
xlabel('Number of rows');
  2 comentarios
Levan Tavdgiridze
Levan Tavdgiridze el 6 de Dic. de 2020
This worked. Thank you
Ameer Hamza
Ameer Hamza el 6 de Dic. de 2020
I am glad to be of help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Monte-Carlo 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!

Translated by