Hello Everyone,
I am not really good at matlab and I am dealing with a time series data. The times series format is dd/mm/yyyy, I have attached a picture of the format.
My time series ranges from 1949 to 2017, my problem is if I want to delete a specific year in this time series, lets say 1949 along with data that comes with it...How do remove it from my time series?
I tried a bunch of time series commands such as delsample...but it didn't work. I don't know how to get about this.
If more information is needed please let me know,
Thank you.

 採用された回答

Walter Roberson
Walter Roberson 2017 年 9 月 16 日

0 投票

Assuming your data is in variable ts, and using the example of wanting to delete multiple years:
mask = ~ismember(year(ts.Time), [1949, 1950]);
new_ts = getsamples(ts, mask);

7 件のコメント

John Doe
John Doe 2017 年 9 月 17 日
It's not working :/ it still gives me the same data ranging from 1949 to 2017
Walter Roberson
Walter Roberson 2017 年 9 月 17 日
It worked on the random data I created to test with. Perhaps you could attach some of your time series data for us to test against.
John Doe
John Doe 2017 年 9 月 18 日
編集済み: Walter Roberson 2017 年 9 月 19 日
I am very sorry for the late reply.
I have attached the data that I am turning into a time series and below is the code:
ActualDays= 24564;
NHours = 24;
%%%Creating a time series
ts = timeseries(RAINVEC,1:ActualDays*NHours);
ts.Name = 'Hourly Rainfall [inch]';
ts.TimeInfo.Units = 'hours';
ts.TimeInfo.StartDate = datestr(dateaq(1)); % Set start date.
ts.TimeInfo.Format = 'mmm dd, yy'; % Set format for display on x-axis.
ts.Time = ts.Time - ts.Time(1); % Express time relative to the start date.
Walter Roberson
Walter Roberson 2017 年 9 月 18 日
If you want to be able to select by particular year, you should avoid doing the
ts.Time = ts.Time - ts.Time(1)
line.
John Doe
John Doe 2017 年 9 月 19 日
I tried running what you suggested avoiding that line but it still doesn't work for some reason :/
Walter Roberson
Walter Roberson 2017 年 9 月 19 日
Year = year(ts.Time/24 + datenum(ts.TimeInfo.StartDate));
mask = ~ismember(Year, 1949);
new_ts = getsamples(ts, mask);
John Doe
John Doe 2017 年 9 月 19 日
Thank You!! This works!
But what was my problem?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2017 年 9 月 16 日

コメント済み:

2017 年 9 月 19 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by