user5179049
user5179049

Reputation: 3

Matlab Semi Markov model

I am working on a Semi Markov model. In it my task is to find the interval transition probability which is a recursive procedure. The code that I used is below. For this to run the initial condition is F(0)=eye(3,3) matrix.

I am unable to call this initial value in a loop. Is the code that I have written is right? I need a proper suggestion.

Other data used is

C = 

  Columns 1 through 4

    [3x3 double]    [3x3 double]    [3x3 double]    [3x3 double]

  Column 5

    [3x3 double]
Y = 

  Columns 1 through 4

    [3x3 double]    [3x3 double]    [3x3 double]    [3x3 double]

  Column 5

    [3x3 double]

The code:

F=mat2cell(zeros(3,15),[3],[3,3,3,3,3])

for j=1:5
   for m=1:j

      if (j-m)==0
         F{:,j}=eye(3,3)
      end

      F{:,j}=Y{:,j}+sum(C{:,m}*F{:,(j-m)})

   end
end

Upvotes: 0

Views: 487

Answers (1)

While you overwrite F{:,j} when j-m==0, you still try to access F{:,(j-m)} later on. Doesn't it say "Cell contents indices must be greater than 0" or "Subscript indices must either be real positive integers or logicals."? Matlab arrays and cells are indexed from 1 upwards.

You might need something like

if (j-m)==0
    F{:,j}=eye(3,3);
else
    F{:,j}=Y{:,j}+sum(C{:,m}*F{:,(j-m)});
end

Don't forget your semicolons or you'll get loads of unnecessary output.

And do you really need cells? What you wrote could easily be implemented using multidimensional arrays, in which case your colons are actually needed. In your specific example, I think they are redundant, it would suffice to write, for instance, F{j-m}.

Upvotes: 2

Related Questions