how to filter data by date?

7 ビュー (過去 30 日間)
Manny
Manny 2024 年 3 月 4 日
回答済み: Steven Lord 2024 年 3 月 4 日
hi everyone
I am trying to filter records by date. I am getting error. How do I fix it?
Code:
Data = convertvars(Data, 2, @(x) datetime(x, 'InputFormat', 'yyyy-MM-dd'));
FilteredDataRealizedVol = Data(:,["TRADE_DATE","REALIZED_VOLATILITY"]);
FilteredDataRealizedVol = FilteredDataRealizedVol(FilteredDataRealizedVol(:,1) <= datetime(2016,7,18),:);
FilteredDataRealizedVol = FilteredDataRealizedVol(FilteredDataRealizedVol(:,1) >= datetime(1928,1,27),:);
Error:
Error using <=
This operation is not defined between 'table' and 'datetime'. The input that is not a table or timetable must be a numeric or
logical array.
Error in LinearRegression (line 26)
FilteredDataRealizedVol = FilteredDataRealizedVol(FilteredDataRealizedVol(:,1) <= datetime(2016,7,18),:);
Thank you

採用された回答

Walter Roberson
Walter Roberson 2024 年 3 月 4 日
FilteredDataRealizedVol = FilteredDataRealizedVol(FilteredDataRealizedVol{:,1} <= datetime(2016,7,18),:);
  5 件のコメント
Manny
Manny 2024 年 3 月 4 日
i did put the {} but still not working:
FilteredDataRealizedVol = FilteredDataRealizedVol(FilteredDataRealizedVol{:,1} <= datetime(2016,7,18),:);
FilteredDataRealizedVol = FilteredDataRealizedVol(FilteredDataRealizedVol{:,1} >= datetime(1928,1,27),:);
Manny
Manny 2024 年 3 月 4 日
i figured it out now.
the problem was in another part of the code that was referencing the unfiltered data.
thank you everyone for your help!

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2024 年 3 月 4 日
Use a timerange to index into the timetable.

カテゴリ

Help Center および File ExchangePreprocessing Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by