【发布时间】:2013-05-27 16:51:51
【问题描述】:
如何从 MATLAB 时间序列或金融时间序列对象中删除特定的星期几(例如星期一)?
【问题讨论】:
-
删除特定的星期几 = 用 NaN 值替换以表示缺失的数据值?
-
好吧,那可以,但是怎么做呢?谢谢!
标签: matlab time-series
如何从 MATLAB 时间序列或金融时间序列对象中删除特定的星期几(例如星期一)?
【问题讨论】:
标签: matlab time-series
这是我想出来的。
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
【讨论】:
一些想法,但只删除特定日期,而不是特定星期几,看起来没有任何聪明的方法可以这样做,因此您可能必须生成日期向量才能删除自己:
% 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)
【讨论】: