Bugs in tscollection class?
3 次查看(过去 30 天)
显示 更早的评论
I found that in class TSCOLLECTION the method ADDTS has two bugs in subfunction "localUnitConv". Or am I mistaken?
But what is it?
function convFactor = localUnitConv(outunits,inunits)
try
% Get available units
availableUnits = {'weeks', 'days', 'hours', 'minutes', 'seconds',...
'milliseconds', 'microseconds', 'nanoseconds'};
factors = [604800 86400 3600 60 1 1e-3 1e-6 1e-9];
indIn = find(strcmp(inunits,availableUnits)); % ??? Case Insensitive is lost?
if isempty(indIn)
return % ??? convFactor is not defined!
end
factIn = factors(indIn);
indOut = find(strcmp(outunits,availableUnits)); % ???
if isempty(indOut)
return % ???
end
factOut = factors(indOut);
convFactor = factIn/factOut;
catch me %#ok<NASGU>
% ??? Exception does not work if convFactor is not define!
convFactor = 1; % Return 1 if error or unknown units
end
For example:
ts1 = timeseries(rand(5,1),[1 2 3 4 5], 'Name', 'ts1')
ts1.TimeInfo.Units = 'Days'
ts2 = timeseries(rand(5,1),[1 2 3 4 5], 'Name', 'ts2')
ts2.TimeInfo.Units = 'Days'
tsc = tscollection({ts1, ts2})
Oops...
---------
Error in ==> tscollection.addts>localUnitConv at 190 try
??? Output argument "convFactor" (and maybe others) not assigned during call to "C:\Programs\MATLAB\R2010b\toolbox\matlab\timeseries\@tscollection\addts.m>localUnitConv".
Error in ==> tscollection.addts>localCheckTS at 131 tsIntimevec = localUnitConv(h.TimeInfo.Units,ts.TimeInfo.Units)*ts.Time;
Error in ==> tscollection.addts at 78 localCheckTS(h,data{i});
Error in ==> tscollection.init at 103 this = this.addts(tsCellArray);
Error in ==> tscollection.tscollection>tscollection.tscollection at 50 this = init(this,varargin{:});
----------
Am I doing something wrong, or is it a bad testing?
2 个评论
Titus Edelhofer
2011-5-30
Hi,
as far as I can see, the doc of tscollection gives all timeinfo in lower case, i.e., 'days' instead of 'Days'. Then it should work. I haven't seen somewhere in the doc that it should be case insensitive ...
Titus
Oleg Komarov
2011-5-30
Then it's a documentation enhancement and not a bug (but I would make it a code enhancement to case INsensitive)
回答(1 个)
Oleg Komarov
2011-5-29
Use 'days' (non capitalized)
You can change:
indIn = find(strcmp(inunits,availableUnits));
indOut = find(strcmp(outunits,availableUnits));
to
indIn = find(strcmpi(inunits,availableUnits));
indOut = find(strcmpi(outunits,availableUnits));
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series Collections 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!