-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_tracks.m
59 lines (49 loc) · 2.04 KB
/
load_tracks.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function [] = load_tracks()
%load_tracks Load X/Y tracking data
% Function that imports manual worm coordinates generated in FIJI and
% collated in a series of .xslx tabs. Tab names must match info.wormUIDs.
global info
global dat
%% Import tracks
% Updated for single camera configuration
[dat.Xvals.Pixels, dat.Yvals.Pixels, dat.frame]=pull_coords(info.wormUIDs, info.tracklength, info.numworms);
disp('...done.');
end
function [xvals, yvals, frame] = pull_coords(wormUIDs, tracklength, numworms)
%%pull_coords imports the x and y coordinates of individual worm tracking data from an excel spreadsheet.
% Required Inputs:
% wormUIDs = names of the tabs containing the tracking data for import
% tracklength = expected number of images, usually 300 for a 10 min
% tracking session and 450 for a 15 min session.
% numworms = number of tracks (i.e. individual worm data) to import
% Outputs:
% xvals = x-coordinates of the worm location, in pixels
% yvals = y-coordinates of the worm location, in pixels
% frame = frame numbers of the x/y coordinates
global info
[xvals,yvals,frame] = deal(NaN(tracklength,numworms));
[~, sheets]=xlsfinfo(info.calledfile);
errorflag = 0;
for i=1:numworms
disp(['loading file ', num2str(i), ' of ', num2str(numworms)]);
sheet = [wormUIDs{i}];
if ~isempty(find(strcmp(sheets,sheet),1))
temp(:,:) = xlsread(info.calledfile, sheet, strcat('C1:E',num2str(tracklength)));
if ~isempty(temp)
xvals(1:length(temp),i)=temp(:,2);
yvals(1:length(temp),i)=temp(:,3);
frame(1:length(temp),i)=temp(:,1);
else
disp(['The tab named ', wormUIDs{i}, ' is empty. Please remove from Index tab or add data.']);
errorflag = 1;
end
clear temp
else
disp(['A data tab named ', wormUIDs{i}, ' was not found. Please check the excel spreadsheet.']);
errorflag = 1;
end
end
if errorflag > 0
error('Errors discovered during data loading. Please see text above for details.');
end
end