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일

0 개 추천

FilteredDataRealizedVol = FilteredDataRealizedVol(FilteredDataRealizedVol{:,1} <= datetime(2016,7,18),:);

댓글 수: 5

Manny
Manny 2024년 3월 4일
thanks for the reply. the errors are gone but the array was not filtered. it is still showing the unfiltered data. any idea on what is going on?
Manny
Manny 2024년 3월 4일
i updated the question. i added the second datatime date filter
Dyuman Joshi
Dyuman Joshi 2024년 3월 4일
Use curly brackets for accessing data inside the tables, as Walter has done as well.
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일

0 개 추천

Use a timerange to index into the timetable.

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

질문:

2024년 3월 4일

답변:

2024년 3월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by