%% example script to load data, create dataset for heatmap (Fig 8), calculate circling index %% load data % load -feat.mat and -track.mat file for a trial (e.g. trials example1 and example2) load('example1-feat.mat') feat_example1=feat; feat_example1.data=feat_example1.data(:, 1:36000,:); load('example1-track.mat') trk_example1=trk; trk_example1.data=trk_example1.data(:, 1:36000,:); trk_example1.sogg = repmat(69,size(trk_example1.data,1), 1); trk_example1.sex = repmat(fm,size(trk_example1.data,1), 1); load('example2-feat.mat') feat_example2=feat; feat_example2.data=feat_example2.data(:, 1:36000,:); load('example2-track.mat') trk_example2=trk; trk_example2.data=trk_example2.data(:, 1:36000,:); trk_example2.sogg = repmat(69,length(trk_example2.data), 1); trk_example2.sex = repmat(fm,size(trk_example2.data,1), 1); %% appending structs to create one single big struct trk_nan=trk_example1; trk_all=trk_example1; trk_all.data=cat(1,trk_example1.data(:,:,:),trk_example2.data, etc); feat_all=feat_example1; feat_all.data=cat(1,feat_example1.data(:,:,:),feat_example2.data, etc.); % create dataset for heatmap t_fm=real(feat_all.data(:,:,12)); r_fm=feat_all.data(:,:,10); %% Calculate the circling index theta, namely angles between 3 consecutive trajectory points n_points = size(trk_all.data,2); % trajectory length (in points) n_moscerini = size(trk_all.data,1); % how many moscerini theta = zeros(size(trk_all.data,1),size(trk_all.data,2)-2); % 900 steps means 898 triplets (898 displacement vectors) normal_versor = cross([1 0 0],[0 1 0]); % versor (unitary vector) exiting the moscerino trajectories plane (perpendicular) for i_moscerino = 1:1:n_moscerini % loop over moscerini for i_step = 1:1:n_points-2 % loop over steps ("-2" because of 898 triplets for 900 points...) r12 = [trk_all.data(i_moscerino,i_step+1,1)-trk_all.data(i_moscerino,i_step,1) , trk_all.data(i_moscerino,i_step+1,2)-trk_all.data(i_moscerino,i_step,2) , 0]; % displacement vector of first step (starting point to middle point) r23 = [trk_all.data(i_moscerino,i_step+2,1)-trk_all.data(i_moscerino,i_step+1,1), trk_all.data(i_moscerino,i_step+2,2)-trk_all.data(i_moscerino,i_step+1,2), 0]; % displacement vector of second step (middle point to ending point) theta(i_moscerino, i_step) = atan2d( dot(cross(r12,r23),normal_versor ) , dot(r12,r23) ); % angle in degrees between the two displacement vectors (always between 180 degrees and -180 degrees, negative if CW, positive if CCW) end end