Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
??? Index exceeds matrix dimensions.

Subject: ??? Index exceeds matrix dimensions.

From: Li Wen

Date: 26 May, 2011 04:43:05

Message: 1 of 3

Hi I am trying to simulate a betting system with the probability of "Player" wins with probability of 0.46686, "Banker" wins with probability of 0.42556, "Tie" wins with probability of 0.10758.

The gambler has the preference of betting Player:Banker:Tie on a probability 0.5:0.45:0.05, each time he lose he lower the probability he bet on by 10% and raise other 2 by 10%, vice versa.

When I simulate my file it gave me the error "??? Index exceeds matrix dimensions" which I can't find any mistake, please help me.

function BetProbability=TestProb
%Generate the results for each round by using the average of 100 probabilities
%estimated from the simulated 2000 rounds/. The probabilities obtain are:
%"Player" wins with probability of 0.46686, "Banker" wins with probability of
%0.42556, "Tie" wins with probability of 0.10758
for t=1:2000,
    C(t) = ceil(100000*rand);
    if C(t)>=1 & C(t)<=46686,
        C(t)=1; %'1' signifies Player
    elseif C(t)>=46687 & C(t)<=89242,
        C(t)=2; %'2' signifies Dealer
    else C(t)=3; %'3' signifies Tie
    end
end

%Now we assume that a superstitious gambler don't believe our first generate and
%believe that all results are determined by God (or any other means), so he still
%keep on a same probability of betting. Player:Banker:Tie = 0.5:0.45:0.05
%However, his betting probability will change if he lose in the previous round
%For example, if he betted "Player" on the first round but lost, the probability
%of betting will change to 0.45:0.495:0.055
%If he win he will increase the probability betting on the same side by 10% and
%decrease others by 10%, vice versa

BetDecision=zeros(1,2000);
BetDecision(1)= ceil(10000*rand);
if BetDecision(1)>=1 & BetDecision(1)<=5000,
       BetDecision(1)=1; %'1' signifies Gambler Betting Player
    elseif BetDecision(1)>=5001 & BetDecision(1)<=9500,
        BetDecision(1)=2; %'2' signifies Gambler Betting Dealer
     else BetDecision(1)=3; %'3' signifies Gambler Betting Tie
end
    
BetProbability=zeros(3,2000);
BetProbability(:,1)=[0.5; 0.45; 0.05];

for k=2:2000,
   if BetDecision(k-1)==C(k-1),
      BetProbability(:,k)=BetProbability(:,k-1)*0.9; BetProbability(BetDecision(k-1),k)=BetProbability(BetDecision(k-1),k)*1.1/0.9;
      if BetDecision(k)>=1 & BetDecision(k)<=10000*BetProbability(k,1),
         BetDecision(k)=0; %'0' signifies Gambler Betting Player
      elseif BetDecision(k)>10000*BetProbability(k,1) & BetDecision(k)<=10000*(BetProbability(k,1)+BetProbability(k,2)),
         BetDecision(k)=1; %'1' signifies Gambler Betting Dealer
      else BetDecision(k)=2; %'2' signifies Gambler Betting Tie
      end
      
   else BetProbability(:,k)=BetProbability(:,k-1)*1.1; BetProbability(BetDecision(k-1),k)=BetProbability(BetDecision(k-1),k)*0.9/1.1;
      if BetDecision(k)>=1 & BetDecision(k)<=(10000*BetProbability(k,1)),
         BetDecision(k)=0; %'0' signifies Gambler Betting Player
      elseif BetDecision(k)>(10000*BetProbability(k,1)) & BetDecision(k)<=(10000*(BetProbability(k,1)+BetProbability(k,2))),
         BetDecision(k)=1; %'1' signifies Gambler Betting Dealer
      else BetDecision(k)=2; %'2' signifies Gambler Betting Tie
      end

   end
end

Subject: ??? Index exceeds matrix dimensions.

From: Roger Stafford

Date: 26 May, 2011 05:27:04

Message: 2 of 3

"Li Wen " <loo_liwen1991@hotmail.com> wrote in message <irklop$bg9$1@newscl01ah.mathworks.com>...
> ........
> When I simulate my file it gave me the error "??? Index exceeds matrix dimensions" which I can't find any mistake, please help me.
> .......
> BetDecision(k)=0; %'0' signifies Gambler Betting Player
> .......
> ... BetProbability(BetDecision(k-1),k)=BetProbability(BetDecision(k-1),k)*0.9/1.1;
> .......
- - - - - - - - - -
  In some cases you are setting 'BetDecision' values to zero and you are subsequently using these same 'BetDecision' values as indices in 'BetProbability'. Indices to arrays should never be zero. Matlab will complain.

Roger Stafford

Subject: ??? Index exceeds matrix dimensions.

From: Li Wen

Date: 26 May, 2011 05:43:05

Message: 3 of 3

Then what should I do to retain BetDecision as an empty matrix with 2000 blanks, as I tried blanks and [] but don't work as well.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us