【问题标题】:How to delete specific days of week from MATLAB timeseries or financial timeseries objects?如何从 MATLAB 时间序列或金融时间序列对象中删除特定的星期几?
【发布时间】:2013-05-27 16:51:51
【问题描述】:

如何从 MATLAB 时间序列或金融时间序列对象中删除特定的星期几(例如星期一)?

【问题讨论】:

  • 删除特定的星期几 = 用 NaN 值替换以表示缺失的数据值?
  • 好吧,那可以,但是怎么做呢?谢谢!

标签: matlab time-series


【解决方案1】:

这是我想出来的。

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

【讨论】:

    【解决方案2】:

    一些想法,但只删除特定日期,而不是特定星期几,看起来没有任何聪明的方法可以这样做,因此您可能必须生成日期向量才能删除自己:

    % 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)
    

    【讨论】:

      猜你喜欢
      • 2017-12-29
      • 2017-10-25
      • 2016-02-21
      • 2021-01-09
      • 2014-03-18
      • 2015-06-05
      • 2019-10-19
      • 2015-09-21
      • 1970-01-01
      相关资源
      最近更新 更多