- 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?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Arjun
il 11 Ott 2024
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 Commenti
Vedere anche
Categorie
Scopri di più su Dates and Time in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!