- Conver the date strings to MATLAB’s serial date numbers for ease in comparison.
- Define starting and ending dates as serial date numbers.
- Use logical indexing to filter the dates within the specified range.
how to filter dates from already present column?
4 ビュー (過去 30 日間)
古いコメントを表示
how to filter dates from already present column(below program) with starting date as 19920102 and ending date as 20110930
Qtfdates = {};
for year =1980:2020
for month=3:3:12
Qtfdates{end+1}= datestr(nweekdate(3, 6, year, month));
end
end
vertcat(Qtfdates{:})
0 件のコメント
回答 (1 件)
Arjun
2024 年 10 月 11 日
I understand that you have a column vector containing dates and you want to filter dates based on a specified date range.
To filter dates from existing cell array of date strings (Qtfdates) based on specified date range, you can follow these steps:
Kindly refer to the following code for better understanding:
Qtfdates = {};
for year = 1980:2020
for month = 3:3:12
Qtfdates{end+1} = datestr(nweekdate(3, 6, year, month));
end
end
% Convert Qtfdates to a column vector
dateStrings = vertcat(Qtfdates{:});
% Convert date strings to serial date numbers
dateNumbers = datenum(dateStrings);
startDate = datenum('19920102', 'yyyymmdd');
endDate = datenum('20110930', 'yyyymmdd');
% Filter dates within the specified range
filteredDates = dateStrings(dateNumbers >= startDate & dateNumbers <= endDate, :);
disp(filteredDates);
Kindly explore the documentation on “datenum” function for conversion to serial date numbers: https://www.mathworks.com/help/releases/R2021b/matlab/ref/datenum.html
I hope this will help!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!