2

How to delete specific days of week (Mondays for instance) from MATLAB timeseries or financial timeseries objects?

4

2 回答 2

2

This is with what I came up with.

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
于 2013-05-27T18:01:07.330 回答
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)
于 2013-05-27T17:47:26.267 回答