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

1 vue (au cours des 30 derniers jours)
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 commentaire
Image Analyst
Image Analyst le 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.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 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.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by