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!