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

2 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2019-3-3
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.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2019-3-4
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by