%This script uses the HMM Matlab toolbox to train an HMM on multiple-trial %data function [observ] = Extract_Observ(spk_vec,time_vec,cell_nums), spk_vec; %Multiple-trial matrix of spike vectors from MEA time_vec; %Time vector associated with spk_vec cell_nums; %Vector of [First_Cell Last_Cell] to train with %Truncate spk_vec to contain only desired cells spk_vec = spk_vec(:,:,cell_nums(1):cell_nums(2)); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Determine observation made at each timestep %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Create observation vector (only 1 observation allowed per step!) observ = zeros(size(spk_vec,1),size(spk_vec,2)); %For each of the trials for i = 1:size(spk_vec,1), %For each of the relevant channels for j = 1:size(spk_vec,3), %Find spikes in channel i tmp = find(spk_vec(i,:,j)); %Assign channel # to proper observation slot and %overwrite any previous channel in that timeslot %(only 1 allowed!!) observ(i,tmp) = j; end; end; %A zero observation ruins indexing below...shift all up by 1 observ = observ + 1; return;