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

조회 수: 3 (최근 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