extracting files having names with the same date from a dataset
2 次查看(过去 30 天)
显示 更早的评论
I am having some txt files as a training dataset for a modele I'm trying to build.
if we asumed that the txt files names has the format YYYYMMDDHHmm as 196611110428.
if I would like to extract files that have the month=12, day=05, hour=22. discarding the years and the minutes, How I can possibly do that?
0 个评论
采纳的回答
Stephen23
2022-1-31
编辑:Stephen23
2022-1-31
Here is one approach, tested on the attached files:
P = '.'; % absolute or relative path to where the files are saved
S = dir(fullfile(P,'*.txt'));
[~,F,~] = fileparts({S.name});
T = datetime(F,'InputFormat','uuuuMMddHHmm');
X = T.Month==12 & T.Day==5 & T.Hour==22
{S(X).name} % training set
{S(~X).name} % not training set
0 个评论
更多回答(2 个)
Sambit Supriya Dash
2022-1-31
a = 196611110428;
strA = string(a);
d = datetime(strA,'InputFormat','yyyyMMddHHmm');
disp(d)
Month = month(d);
Day = day(d);
Hour = hour(d);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!