Table not aligning properly

조회 수: 2 (최근 30일)
TheSaint
TheSaint 2024년 2월 26일
편집: Walter Roberson 2024년 2월 26일
ThePriceisRightWheel()
Contestant 1 Spin vs. Probability of Winning 5.0000 0.0495 10.0000 0.1000 15.0000 0.1502 20.0000 0.1981 25.0000 0.2498 30.0000 0.3020 35.0000 0.3500 40.0000 0.3987 45.0000 0.4516 50.0000 0.4995 55.0000 0.5498 60.0000 0.6012 65.0000 0.6492 70.0000 0.7011 75.0000 0.7482 80.0000 0.7978 85.0000 0.8499 90.0000 0.8987 95.0000 0.9518 100.0000 1.0000
function ThePriceisRightWheel()
clc
clear
RunTotal = 100000;
Contestant1Spins = 5:5:100;
SpinNumber = numel(Contestant1Spins);
Wins = [];
for Trial1= 1:SpinNumber
Spin1 = Contestant1Spins(Trial1);
count = 0;
for Trial2 = 1:RunTotal
Spin2 = randi([0, 100]);
if Spin2 > Spin1
continue
elseif Spin1 == Spin2
Spin3 = randi([0,100]);
if Spin3 > Spin1
continue
end
end
count = count + 1;
end
TotalWins(Trial1) = count;
end
Probability = TotalWins/ RunTotal;
disp('Contestant 1 Spin vs. Probability of Winning');
disp([Contestant1Spins' Probability']);
end
I have this code to simulate a wheel from the Price is right, but I need a table that displays "Contestant 1 Spin vs. Probability of Winning", but the actual numbers do not line up properly underneath my header. If anyone could let me know how to fix this I would appreciate it.

답변 (1개)

Star Strider
Star Strider 2024년 2월 26일
Use fprintf instead of disp
ThePriceisRightWheel
Contestant 1 Spin vs. Probability of Winning 5 0.0496 10 0.0983 15 0.1495 20 0.2013 25 0.2503 30 0.3010 35 0.3511 40 0.4019 45 0.4476 50 0.4989 55 0.5478 60 0.6003 65 0.6516 70 0.6997 75 0.7516 80 0.7984 85 0.8481 90 0.8995 95 0.9494 100 1.0000
function ThePriceisRightWheel()
clc
clear
RunTotal = 100000;
Contestant1Spins = 5:5:100;
SpinNumber = numel(Contestant1Spins);
Wins = [];
for Trial1= 1:SpinNumber
Spin1 = Contestant1Spins(Trial1);
count = 0;
for Trial2 = 1:RunTotal
Spin2 = randi([0, 100]);
if Spin2 > Spin1
continue
elseif Spin1 == Spin2
Spin3 = randi([0,100]);
if Spin3 > Spin1
continue
end
end
count = count + 1;
end
TotalWins(Trial1) = count;
end
Probability = TotalWins/ RunTotal;
fprintf('Contestant 1 Spin vs. Probability of Winning\n')
fprintf('\t%3d\t\t\t%.4f\n',[Contestant1Spins' Probability'].');
end
An even better optioon is to use array2table.
.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by