Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/fromTSfcn.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % FROMTSFCN Construct an ao from a ts-function string | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % FUNCTION: fromTSfcn | |
5 % | |
6 % DESCRIPTION: Construct an ao from a ts-function string | |
7 % | |
8 % CALL: a = fromTSfcn(pl) | |
9 % | |
10 % PARAMETER: pl: Parameter list object | |
11 % | |
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
13 function a = fromTSfcn(a, pli) | |
14 | |
15 VERSION = '$Id: fromTSfcn.m,v 1.25 2011/08/16 06:13:02 hewitson Exp $'; | |
16 | |
17 % get AO info | |
18 ii = ao.getInfo('ao', 'From Time-series Function'); | |
19 | |
20 % Set the method version string in the minfo object | |
21 ii.setMversion([VERSION '-->' ii.mversion]); | |
22 | |
23 % Add default values | |
24 pl = applyDefaults(ii.plists, pli); | |
25 pl.getSetRandState(); | |
26 | |
27 nsecs = find(pl, 'nsecs'); | |
28 fs = find(pl, 'fs'); | |
29 fcn = find(pl, 'tsfcn'); | |
30 t0 = find(pl, 't0'); | |
31 toffset = find(pl, 'toffset'); | |
32 | |
33 % Build t vector | |
34 if isempty(nsecs) || nsecs == 0 | |
35 error('### Please provide ''Nsecs'' for ts-function constructor.'); | |
36 end | |
37 if isempty(fs) || fs == 0 | |
38 error('### Please provide ''fs'' for ts-function constructor.'); | |
39 end | |
40 | |
41 | |
42 % make time vector | |
43 t = [0:1/fs:nsecs-1/fs]'; | |
44 | |
45 % make y data | |
46 y = eval([fcn ';']); | |
47 | |
48 % if the user passed a string which is not a function of t, then a | |
49 % constant value is calculated | |
50 if numel(t) ~= numel(y) | |
51 if numel(y) == 1 | |
52 disp('The function input is not a function of t; a constant value is calculated.'); | |
53 y = y*ones(size(t)); | |
54 else | |
55 error('### The function input size does not match the time base size'); | |
56 end | |
57 end | |
58 | |
59 % Make an analysis object | |
60 a.data = tsdata(t,y); | |
61 | |
62 % set t0 | |
63 a.setT0(t0); | |
64 | |
65 % set toffset | |
66 a.setToffset(toffset); | |
67 | |
68 % Set xunits and yunits | |
69 a.setXunits(pl.find('xunits')); | |
70 a.setYunits(pl.find('yunits')); | |
71 | |
72 % Add history | |
73 a.addHistory(ii, pl, [], []); | |
74 % Set object properties from the plist | |
75 a.setObjectProperties(pl); | |
76 | |
77 end | |
78 | |
79 |