I am using the accumarray by using the following command on the first and second column of struct array. The first part of the code works good.
but the last two commands "went_from_to_countAge" and "went_from_to_probAge", does not work. any idea?
sequence = [1 1 1 1 2 2 2 2 2 3;... 1 1 1 1 1 1 1 1 1 1;... 1 1 1 1 1 1 1 1 1 1;... 1 1 1 1 1 1 1 2 2 2;... 1 1 1 1 1 1 1 1 1 1;... 2 2 2 2 2 2 2 2 2 2; ... 2 2 2 2 2 2 2 3 3 3; ... 2 3 3 3 3 3 2 2 2 2; ... 2 2 2 2 2 2 4 4 4 4]% first part of the code
k = 1:size(sequence)Age (k) = 25 + kStates = unique([sequence(:,k); sequence(:,k+1)]); % Find the unique rows based on the data in the first two columns.
[TF, fromstateAge] = ismember(sequence(:,k), States); % logical arrays
[TF, tostateAge] = ismember(sequence(:,k+1), States);% second part of the code
went_from_to_countAge(:,k) = accumarray( [fromstateAge(:), tostateAge(:)], 1, []) % frequency of each unique number
went_from_to_probAge(k)= went_from_to_countAge ./ sum(went_from_to_countAge); % pribability of each unique number
Best Answer