Index in position 1 exceeds array bounds (must not exceed 25). Please help!!

3 views (last 30 days)
function [Slotplayers,RoulettePlayers,HouseEarning]= hw5_func(SlotRounds,RouletteRounds)
Slotplayers=zeros(SlotRounds+1,10);
SlotPlayers(1, :)=round(5000+(25000-5000).*rand(1,10));
HouseEarning = 0;
for i=1:SlotRounds
Spin=rand(i,10);
for k=1:10
if SlotPlayers(i,k)>=100
if Spin(i,k)<= 0.00001
SlotPlayers(i+1,k) = SlotPlayers(i,k) + 250000;
elseif Spin(i,k)>0.00001 && Spin(i,k)<=0.00015
SlotPlayers(i+1,k)= SlotPlayers(i,k)+ 100000;
elseif Spin(i,k)>0.00015 && Spin(i,k)<=0.0005
SlotPlayers(i+1,k)= SlotPlayers(i,k) + 40000;
elseif Spin(i,k)>0.0005 && Spin(i,k)<=.005
SlotPlayers(i+1,k)= SlotPlayers(i,k) + 5000;
elseif Spin(i,k)>0.005 && Spin(i,k)<=0.07
SlotPlayers(i+1,k)= SlotPlayers(i,k) + 500;
elseif Spin(i,k)>0.07 && Spin(i,k)<=0.92434
SlotPlayers(i+1,k)= SlotPlayers(i,k) + 0;
end
end
end
HouseEarning(i+1)= HouseEarning(i)+(sum(SlotPlayers(i,:))-sum(SlotPlayers(i+1,:)));
end
This is the error I am getting:
Index in position 1 exceeds array bounds (must not exceed 67).
Error in hw5_func (line 35)
HouseEarning(i+1)= HouseEarning(i)+(sum(SlotPlayers(i,:))-sum(SlotPlayers(i+1,:)));
Thanks!
  1 Comment
Image Analyst
Image Analyst on 3 Mar 2019
What did you pass in for SlotRounds,RouletteRounds? What is the value of i when it threw the error? What are the sizes of HouseEarning and SlotPlayers?
This is just normal debugging practice. See this link to learn debugging methods. You will need to learn them sooner or later.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 4 Mar 2019
You initialize SlotPlayers with SlotRounds rows. When i becomes SlotRounds then you try to access SlotPlayers(i+1,:) which would be SlotPlayers(SlotRounds+1,:) which potentially does not exist because it was only initialized to SlotRounds.
In particular it will not be assigned to if SlotPlayers(SlotRounds,:) are all < 100.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!