如何从MATLAB时间序列或财务时间序列对象中删除一周中的特定日期(例如星期一)?
答案 0 :(得分:2)
这与我的想法一致。
function [ ret_fts ] = deleteWeekDays( fts, dayName )
tsz = size(fts);
sz = tsz(1);
for i=1:sz,
mat=fts2mat(fts(i),1);
[dnum, dnam] = weekday(mat(1));
if dnam==dayName
fts(i) = NaN;
end
end
ret_fts=fts;
end
答案 1 :(得分:1)
一些想法,但只删除一个特定的日期,而不是一周的特定日期,看起来没有任何聪明的方法,所以你可能必须生成日期向量来自行删除:
% Set time series
ts = timeseries([3 6 8 0 10 3 6 8 0 10 3 6 8 0 10 3 6 8 0 10 3 6 8 0 10])
ts.Data
tsc = tscollection(ts);
tsc.TimeInfo.Units = 'days';
tsc.TimeInfo.StartDate = '10/27/2005 07:05:36';
% Plot
ts.DataInfo.Interpolation = tsdata.interpolation('zoh');
tsc1.TimeInfo.Format='DD:HH:MM';
figure
plot(ts)
% Change the date-string format of the time vector.
tsc.TimeInfo.Format = 'mm/dd/yy';
tscTime = getabstime(tsc)
% Spot the days you're interested in, get indices and replace them by NaN
% in ts.
dayToDelete = '11/11/05';
idx = strcmp(tscTime, dayToDelete);
ts.Data(idx) = NaN;
% Plot after deleting the specific date
ts.DataInfo.Interpolation = tsdata.interpolation('zoh');
figure
plot(ts)