Split file name (alphanumeric name)
이전 댓글 표시
I have a file names like: CAN20111230T134021UTC.mat
I need to split the file name and consider the files with month(12) i.e., 12.mat and run the loop based on that.
Could anyone please help me with this. Thanks in advance
채택된 답변
추가 답변 (1개)
This is easy with my FEX submission datenum8601 that converts ISO 8601 date strings and converts them to date numbers, which can be converted to date vectors using datevec:
>> C = {'CAN20111230T134021UTC.mat';'CAN20111101T123456UTC.mat'};
>> V = datevec(cellfun(@datenum8601,C))
V =
2011 12 30 13 40 21
2011 11 1 12 34 56
The matrix of datevectors can be used to generate some logical indices for selecting only the desired filenames:
>> X = V(:,2)==12
X =
1
0
The logical indices can be used to select elements of a non-scalar structure, a cell array, or any other array.
Note that datenum8601 also returns the split parts of the strings (i.e. 'CAN' and 'UTC.mat'), and can be configured to recognize only particular date formats.
Filenames stored in a non-scalar structure can be converted to a cell array very simply, where name is the field of structure A containing the filenames:
C = {A.name};
댓글 수: 2
anu
2015년 4월 1일
You have already accepted another answer, which means that the question has been resolved. Accepting an answer tells other users that the problem has been resolved, so they will not bother to read this question. Is there still a problem?
I know that your data is in structures, that is exactly why I wrote the last sentences of my answer, to specifically address this topic. Did you read it, or look at the link? Do you understand the example that I gave?
So far you have not told us any details about this data structure: in particular you need to tell us if it is scalar or non-scalar, what the fieldnames are, and if they are nested with either cells or structs. Simply saying "my data file are structures" is not enough information for us.
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!