How to reference each element of a column vector in an if statement
Show older comments
I need to get AmountWon to reflect each element in the column vector spin. Everytime this runs I get AmountWon = 250000 because it is adding all the Spin values in the Spin vector.
For example, I want AmountWon to be different for each of the 10 different spin values... this could be stored in another variable x that replaces the value in each row by the amount won, if any.
x = zeros(11,10)
Slotrounds = 10
for j = 1:SlotRounds
Spin(1,:) = rand(1,10) %generates a 1x10 column vector of rand. numbers
for jj = 1:SlotRounds %a compares probability to winnings
if Spin <= .99999
AmountWon = 250000
elseif Spin <= .99985
AmountWon = 100000
elseif Spin <= .99950
AmountWon = 40000
elseif Spin <= .99500
AmountWon = 5000
elseif Spin <= .93000
AmountWon = 500
else
AmountWon = 0;
end
end
x = %I want the x values to change in each row as the loop progresses
end
1 Comment
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!