Table not aligning properly

2 views (last 30 days)
TheSaint
TheSaint on 26 Feb 2024
Edited: Walter Roberson on 26 Feb 2024
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.

Answers (1)

Star Strider
Star Strider on 26 Feb 2024
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.
.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!