have to plot the number of head in a game of head or tails that the token is trowed N times, but my plot dont work

1 visualización (últimos 30 días)
the plot has to show the number of faces per time the token is throwed
N = input('Coloque um valor para N: ');
cara = 0;
coroa = 0;
x=rand(1,N);
for i = 1:length(x)
if x(i) < 0.5
x(i) = 0; % cara
else
x(i) = 1; % coroa
end
end
figure
histogram(x);
title('Gráfico')
for i = 1: length(x)
if x(i) == 0
caras = cara + 1;
else
coroa = coroa + 1;
end
end
plot(cara , length(x))

Respuesta aceptada

Voss
Voss el 29 de Jul. de 2022
Editada: Voss el 29 de Jul. de 2022
% caras = cara + 1;
cara = cara + 1;
That will get the total number of heads (a.k.a. faces) to be correct, but you'll still be plotting only one point (which won't show up without a data marker).
To plot the number of heads vs the number of token throws (a.k.a. coin tosses a.k.a. coin flips) for the entire sequence of flips:
plot(cumsum(x==0))

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by