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 次查看(过去 30 天)
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))

采纳的回答

Voss
Voss 2022-7-29
编辑:Voss 2022-7-29
% 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))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by