Download code
From LiteratePrograms
Back to TimeSeries_and_TimeSeries_Collections_(Matlab)
Download for Windows: zip
Download for UNIX: zip, tar.gz, tar.bz2
translate4tsc.m
1 % Copyright (c) 2008 the authors listed at the following URL, and/or 2 % the authors of referenced articles or incorporated external code: 3 % http://en.literateprograms.org/TimeSeries_and_TimeSeries_Collections_(Matlab)?action=history&offset=20080704102235 4 % 5 % Permission is hereby granted, free of charge, to any person obtaining 6 % a copy of this software and associated documentation files (the 7 % "Software"), to deal in the Software without restriction, including 8 % without limitation the rights to use, copy, modify, merge, publish, 9 % distribute, sublicense, and/or sell copies of the Software, and to 10 % permit persons to whom the Software is furnished to do so, subject to 11 % the following conditions: 12 % 13 % The above copyright notice and this permission notice shall be 14 % included in all copies or substantial portions of the Software. 15 % 16 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 % 24 % Retrieved from: http://en.literateprograms.org/TimeSeries_and_TimeSeries_Collections_(Matlab)?oldid=13872 25 26 function z = translate4tsc(op, s) 27 % TRANSLMATE4TSC - translation in to directions: 28 % 'anycharaters0x280x5C_0x29' = translate4tsc('to-tsc', 'anycharaters(\_)') 29 % 'anycharaters(\_)' = translate4tsc('from-tsc', 'anycharaters0x280x5C_0x29') 30 switch lower(op) 31 case {'20xhex', 'to-tsc'} 32 %<* convert to hex 33 code2keep = [48:57,65:90,97:122,95]; 34 t = double(s); 35 t = t(:); 36 ikeep = ismember(t,code2keep); 37 iconv = ~ikeep; 38 if all(ikeep) 39 z = s; 40 return 41 end 42 z = repmat(' ',4,length(s)); 43 tmp = dec2hex([t(iconv);100]); 44 z(3:4,iconv) = tmp(1:end-1,:)'; 45 z(1,iconv) = '0'; 46 z(2,iconv) = 'x'; 47 z(1,ikeep) = s(ikeep); 48 z = strrep(z(:)',' ',''); 49 %>* 50 case {'0x2str', 'from-tsc'} 51 %<* convert 0x hex to string 52 idx = strfind(s, '0x'); 53 if isempty(idx) 54 z = s; 55 return 56 end 57 h = char(hex2dec(s([idx(:)+2,idx(:)+3]))); 58 s([idx(:);idx(:)+1;idx(:)+2])='_'; 59 s(idx(:)+3) = h; 60 s = strrep(s, '___', ''); 61 z = s; 62 %>* 63 otherwise 64 error('translate4tsc:InvalidMode','Invalid mode <%s>',op); 65 end 66
mySynchro.m
1 % Copyright (c) 2008 the authors listed at the following URL, and/or 2 % the authors of referenced articles or incorporated external code: 3 % http://en.literateprograms.org/TimeSeries_and_TimeSeries_Collections_(Matlab)?action=history&offset=20080704102235 4 % 5 % Permission is hereby granted, free of charge, to any person obtaining 6 % a copy of this software and associated documentation files (the 7 % "Software"), to deal in the Software without restriction, including 8 % without limitation the rights to use, copy, modify, merge, publish, 9 % distribute, sublicense, and/or sell copies of the Software, and to 10 % permit persons to whom the Software is furnished to do so, subject to 11 % the following conditions: 12 % 13 % The above copyright notice and this permission notice shall be 14 % included in all copies or substantial portions of the Software. 15 % 16 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 % 24 % Retrieved from: http://en.literateprograms.org/TimeSeries_and_TimeSeries_Collections_(Matlab)?oldid=13872 25 26 function data0 = mySynchro(data1, data2, varargin) 27 % MYSYNCHRO - a simple self made synchronization 28 date0 = union(data1.date, data2.date); 29 value0_1 = interp1(data1.date, data1.value, date0(:), varargin{:}); 30 value0_2 = interp1(data2.date, data2.value, date0(:), varargin{:}); 31 data0 = myTSCobject('title', 'syncronized dataset', 'date', date0(:), 'value', [value0_1, value0_2], ... 32 'names', {data1.names{:}, data2.names{:}}); 33
simple_structure_example1.m
1 % Copyright (c) 2008 the authors listed at the following URL, and/or 2 % the authors of referenced articles or incorporated external code: 3 % http://en.literateprograms.org/TimeSeries_and_TimeSeries_Collections_(Matlab)?action=history&offset=20080704102235 4 % 5 % Permission is hereby granted, free of charge, to any person obtaining 6 % a copy of this software and associated documentation files (the 7 % "Software"), to deal in the Software without restriction, including 8 % without limitation the rights to use, copy, modify, merge, publish, 9 % distribute, sublicense, and/or sell copies of the Software, and to 10 % permit persons to whom the Software is furnished to do so, subject to 11 % the following conditions: 12 % 13 % The above copyright notice and this permission notice shall be 14 % included in all copies or substantial portions of the Software. 15 % 16 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 % 24 % Retrieved from: http://en.literateprograms.org/TimeSeries_and_TimeSeries_Collections_(Matlab)?oldid=13872 25 26 data = struct('title', 'my TScollection title', 'value', cumsum(randn(100,3)), 'date', (now-100+1:now)', ... 27 'names', {{'column1', 'column2', 'column3'}}) 28
simple_structure_example2.m
1 % Copyright (c) 2008 the authors listed at the following URL, and/or 2 % the authors of referenced articles or incorporated external code: 3 % http://en.literateprograms.org/TimeSeries_and_TimeSeries_Collections_(Matlab)?action=history&offset=20080704102235 4 % 5 % Permission is hereby granted, free of charge, to any person obtaining 6 % a copy of this software and associated documentation files (the 7 % "Software"), to deal in the Software without restriction, including 8 % without limitation the rights to use, copy, modify, merge, publish, 9 % distribute, sublicense, and/or sell copies of the Software, and to 10 % permit persons to whom the Software is furnished to do so, subject to 11 % the following conditions: 12 % 13 % The above copyright notice and this permission notice shall be 14 % included in all copies or substantial portions of the Software. 15 % 16 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 % 24 % Retrieved from: http://en.literateprograms.org/TimeSeries_and_TimeSeries_Collections_(Matlab)?oldid=13872 25 26 dt1 = (1:10:200)'; 27 data1 = myTSCobject('title','A','value',[sin(dt1/100*pi),cos(dt1/100*pi)], ... 28 'names',{'sin', 'cos'},'date',dt1,'plot_style','points') 29 dt2 = (10:1:200)'; 30 data2 = myTSCobject('title','B','value',[(dt2/1000).^2,1./dt2], ... 31 'names',{'x2', '1/x'},'date',dt2,'plot_style','points') 32 33 data0 = mySynchro(data1,data2) 34 data0p = mySynchro(data1,data2,'nearest') 35
my_first_tscollection
ts1 = timeseries(cumsum(randn(100,1)), (1:100)','name','one');
ts2 = timeseries(cumsum(randn(100,1)*.5),(1:100)','name','two');
tsc = tscollection({ts1, ts2}, 'Name', 'my first TSCollection');
tsc_plot.m
1 % Copyright (c) 2008 the authors listed at the following URL, and/or 2 % the authors of referenced articles or incorporated external code: 3 % http://en.literateprograms.org/TimeSeries_and_TimeSeries_Collections_(Matlab)?action=history&offset=20080704102235 4 % 5 % Permission is hereby granted, free of charge, to any person obtaining 6 % a copy of this software and associated documentation files (the 7 % "Software"), to deal in the Software without restriction, including 8 % without limitation the rights to use, copy, modify, merge, publish, 9 % distribute, sublicense, and/or sell copies of the Software, and to 10 % permit persons to whom the Software is furnished to do so, subject to 11 % the following conditions: 12 % 13 % The above copyright notice and this permission notice shall be 14 % included in all copies or substantial portions of the Software. 15 % 16 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 % 24 % Retrieved from: http://en.literateprograms.org/TimeSeries_and_TimeSeries_Collections_(Matlab)?oldid=13872 25 26 function h = tsc_plot( tsc, varargin) 27 % TSC_PLOT - plot TSCollection 28 % example: 29 % tsc_plot(tsc, 'linewidth',2) 30 h = figure; 31 names = gettimeseriesnames(tsc); 32 colors = 'brmckyg'; 33 for n=1:length(names) 34 ts = tsc.(names{n}); 35 plot(tsc.time, ts.data, colors(mod(n,length(colors))), varargin{:}); 36 hold on 37 end 38 hold off 39 legend(gca, names); 40 title(tsc.name); 41
myTSCobject.m
1 % Copyright (c) 2008 the authors listed at the following URL, and/or 2 % the authors of referenced articles or incorporated external code: 3 % http://en.literateprograms.org/TimeSeries_and_TimeSeries_Collections_(Matlab)?action=history&offset=20080704102235 4 % 5 % Permission is hereby granted, free of charge, to any person obtaining 6 % a copy of this software and associated documentation files (the 7 % "Software"), to deal in the Software without restriction, including 8 % without limitation the rights to use, copy, modify, merge, publish, 9 % distribute, sublicense, and/or sell copies of the Software, and to 10 % permit persons to whom the Software is furnished to do so, subject to 11 % the following conditions: 12 % 13 % The above copyright notice and this permission notice shall be 14 % included in all copies or substantial portions of the Software. 15 % 16 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 % 24 % Retrieved from: http://en.literateprograms.org/TimeSeries_and_TimeSeries_Collections_(Matlab)?oldid=13872 25 26 function data = myTSCobject( varargin) 27 % MYTSOBJECT - self made efficient TScollection 28 % use: 29 % data = myTSCobject('title', 'my TScollection title', 'value', cumsum(randn(100,3)), ... 30 % 'date', (now-100+1:now)', ... 31 % 'names', {'column1', 'column2', 'column3'}) 32 data = []; 33 for f=1:2:length(varargin)-1 34 field_name = varargin{f}; 35 field_value = varargin{f+1}; 36 data.(field_name) = field_value; 37 end 38 if ~isfield(data,'value') | ~isfield(data,'date') | ~isfield(data,'names') | ~isfield(data,'title') 39 error('myTSCobject:field', 'fields <value> <date> <names> <title> mandatory for myTSCobject'); 40 end 41 [nv,pv] = size(data.value); 42 [nd,pd] = size(data.date); 43 [nn,pn] = size(data.names); 44 if nv ~= nd | pv ~= pn | nn ~= 1 | pd ~= 1 45 warning('myTSCobject:check', 'problem with dimension of fields'); 46 end 47
