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))
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!