I have the following code and I am having this error
Subscript indices must either be real positive integers or logicals.Error in ==> Markov_Chain at 64cur_state = Rand_Vect(P(cur_state,:), 1);
How should I solve it?
Thanks
function [Chain] = Markvok_Chain( P, initial_state, n ) P = [ 0.85 0.15; 0.05 0.95 ]; initial_state = [0.4 0.6]; n=20; sz = size(P); cur_state = round(initial_state);%
% Verify that the input parameters are valid
%if (sz(1) ~= sz(2)) error('Markov_Chain: Probability matrix is not square');endnum_states = sz(1);if (cur_state < 1) | (cur_state > num_states) error('Markov_Chain: Initial state not defined in P')endfor i=1:num_states if (sum(P(i,:)) ~=1 ) error('Markov_Chain: Transition matrix is not valid') endend%% Create the Markov Chain
Chain(1,1:2) = cur_state;for i = 1:n cur_state = Rand_Vect(P(cur_state,:), 1); Chain(i,1:2) = cur_state;end
Best Answer