-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet_PreALLSAP_Dataset.m
96 lines (73 loc) · 3.29 KB
/
Get_PreALLSAP_Dataset.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function [PreMetaSet] = Get_PreALLSAP_Dataset()
% Get_SAP_Dataset:
% Requests from the user a bird number, condition, and date.
% Returns dataset variable of SAP spreadsheet data
%-------------------------------------------------------------------------%
% User input selected bird number
%-------------------------------------------------------------------------%
SAP_DATA_LOC = 'C:\Users\Dr. JT\Documents\DataAnalysis\TF_Birdsong\SAP_Data';
DS_DATA_LOC = 'C:\Users\Dr. JT\Documents\DataAnalysis\TF_Birdsong\DataSet_Data';
%-------------------------------------------------------------------------%
% User input selected bird number
%-------------------------------------------------------------------------%
[Predates, birdNum] = Get_Bird_PreALL;
%-------------------------------------------------------------------------%
% Generate cell list of xls file names
%-------------------------------------------------------------------------%
song_xls_fn = cell(length(Predates),1);
for dN = 1:length(song_xls_fn)
song_xls_fn{dN,1} = strcat(Predates{dN},'.xls');
end
%-------------------------------------------------------------------------%
% User input selected bird number
%-------------------------------------------------------------------------%
PRE_SAP_LOC = strcat(SAP_DATA_LOC,'\',birdNum,'\Pre\');
cd(PRE_SAP_LOC);
songdatdir = cellstr(ls);
sngNames = songdatdir(3:end);
%-------------------------------------------------------------------------%
% User input selected bird number
%-------------------------------------------------------------------------%
sFIndex = zeros(length(sngNames),1);
for sL = 1:length(sngNames)
sFIndex(sL,1) = find(cellfun(@(x) strcmp(song_xls_fn{sL},x), sngNames));
end
songAllPre = {};
for sfds = 1:length(sFIndex)
songF2load = sngNames{sFIndex(sfds)};
cd(PRE_SAP_LOC);
[~, ~, raw.(strcat('day',num2str(sfds)))] = xlsread(songF2load,'Sheet1');
% Check for NAN rows
[nRows,nCols] = size(raw.(strcat('day',num2str(sfds))));
row2rid = nan(1000,1);
rCount = 1;
for nci = 1:nRows
tempRow = raw.(strcat('day',num2str(sfds)))(nci,:);
numChars = ~cellfun(@(x) ischar(x), tempRow);
numNans = cellfun(@(x) isnan(x), tempRow(numChars));
if sum(numNans) == nCols
row2rid(rCount) = nci;
rCount = rCount + 1;
end
end
row2rid = row2rid(~isnan(row2rid));
raw.(strcat('day',num2str(sfds)))(row2rid,:) = [];
songDataset.(strcat('day',num2str(sfds))) = CreatePreALLDS(raw.(strcat('day',num2str(sfds))));
songAllPre = vertcat(songAllPre,songDataset.(strcat('day',num2str(sfds))));
end
NewcolTitles = {'name','syldur','sylstart','Mamp','Mpitch',...
'MFM','MAM','Mentropy','MpitchG', 'Mfreq',...
'Vpitch','VFM','Ventropy','Vpitchg',...
'Vfreq','VAM','filename'};
sapXlsTitles = vertcat(NewcolTitles, songAllPre);
PreMetaSet = cell2dataset(sapXlsTitles);
%-------------------------------------------------------------------------%
% Save Meta Pre File
%-------------------------------------------------------------------------%
fileName = strcat(birdNum,'_PreALL.mat');
BIRD_DATA_LOC = strcat(DS_DATA_LOC,'\',birdNum);
if ~exist(BIRD_DATA_LOC,'dir')
mkdir(BIRD_DATA_LOC)
end
cd(BIRD_DATA_LOC)
save(fileName,'PreMetaSet');