How to reference each element of a column vector in an if statement
이전 댓글 표시
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
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!