-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtgInsertNewPointTier.m
More file actions
51 lines (43 loc) · 1.28 KB
/
Copy pathtgInsertNewPointTier.m
File metadata and controls
51 lines (43 loc) · 1.28 KB
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
function tgNew = tgInsertNewPointTier(tg, tierInd, tierName)
% function tgNew = tgInsertNewPointTier(tg, tierInd, tierName)
%
% Inserts new point tier to the specified index (existing tiers are
% shifted).
%
% tierInd ... new tier index (1 = the first, Inf = the last)
% tierName ... new tier name
%
% v1.0, Tomas Boril, borilt@gmail.com
%
% tg = tgRead('demo/H.TextGrid');
% tg2 = tgInsertNewPointTier(tg, 1, 'POINTS');
% tg2 = tgInsertPoint(tg2, 'POINTS', 3, 'MY POINT');
% tg2 = tgInsertNewPointTier(tg2, Inf, 'POINTS2'); % the last tier
% tg2 = tgInsertPoint(tg2, 'POINTS2', 2, 'point in the last tier');
% tgPlot(tg2);
if nargin ~= 3
error('Wrong number of arguments.')
end
if ~isInt(tierInd)
error(['tierInd must be integer >= 1 or +Inf [' num2str(tierInd) ']']);
end
ntiers = tgGetNumberOfTiers(tg);
if isinf(tierInd)
if tierInd > 0
tierInd = ntiers+1;
else
error('tierInd must be integer >= 1 or +Inf')
end
end
if tierInd < 1 || tierInd>ntiers+1
error(['tierInd out of range [1; ntiers+1], tierInd = ' num2str(tierInd) ', ntiers = ' num2str(ntiers)]);
end
tgNew = tg;
tNew.name = tierName;
tNew.type = 'point';
tNew.T = [];
tNew.Label = {};
for I = ntiers + 1: -1: tierInd+1
tgNew.tier{I} = tgNew.tier{I-1};
end
tgNew.tier{tierInd} = tNew;