function [lrnScore,dist,occu] = lrnScoreUpdate(flyTracks) %flyTracks = [flyTracks.forwardLrn]; corridorPos = [90,110]; for i = 1:length(flyTracks) if isnan(flyTracks(i).centroid) pre(i) = nan;post(i)=nan;preDist(i)=nan;postDist(i)=nan; continue end singFly = flyTracks(i); ind1 = logical(floor(singFly.realTime) > singFly.stimulus{2,1}(1) & floor(singFly.realTime) < singFly.stimulus{2,1}(end)); ind2 = logical(floor(singFly.realTime) > singFly.stimulus{2,end}(1) & floor(singFly.realTime) < singFly.stimulus{2,end}(end)); pre(i) = nansum(singFly.centroid(ind1,2) < corridorPos(1)) / nansum( singFly.centroid(ind1,2) < corridorPos(1) | singFly.centroid(ind1,2) > corridorPos(end)); post(i) = nansum(singFly.centroid(ind2,2) < corridorPos(1)) / nansum( singFly.centroid(ind2,2) < corridorPos(1) | singFly.centroid(ind2,2) > corridorPos(end)); preDist(i) = nansum(abs(diff(singFly.centroid(ind1,2)))); postDist(i) = nansum(abs(diff(singFly.centroid(ind2,2)))); end output1.post.occupancy = post; output1.pre.occupancy = pre; output1.octStm = nansum(flyTracks(5).realTime(logical(flyTracks(5).shock)) > flyTracks(5).stimulus{2,2}(1) & flyTracks(5).realTime(logical(flyTracks(5).shock(:,1))) < flyTracks(5).stimulus{2,2}(end)) > 25; testOCT = flyTracks(5).stimulus{4,2};testOCT = strcmp(testOCT{1},'OCT') & strcmp(testOCT{2},'OCT'); if output1.octStm & testOCT output1.octStm = true; else output1.octStm = false; end if ~output1.octStm output1.post.occupancy = 1-output1.post.occupancy; output1.pre.occupancy = 1-output1.pre.occupancy; end for i = 1:length(output1.pre.occupancy) if output1.post.occupancy(i)-output1.pre.occupancy(i) <= 0 lrnScore(i) = (output1.post.occupancy(i)-output1.pre.occupancy(i))./output1.pre.occupancy(i); if postDist(i) < 500 | preDist < 500 lrnScore(i) = nan; end else lrnScore(i) = (output1.post.occupancy(i)-output1.pre.occupancy(i))./(1-output1.pre.occupancy(i)); if postDist(i) < 500 | preDist < 500 lrnScore(i) = nan; end end end dist = [preDist',postDist']; occu = [pre',post'];