How to make matlab access two folders for data when separated by date
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm trying to move some of the older data into a new folder (ex: move pre2020 files from folder_new to folder_old, and leave the 2020~ files in the folder_new).
Problem is that there are some functions where the user needs to analyze files in both folders (ex: data from Dec 2019 to Feb 2020)
How should I proceed with this?
I was thinking about using an if statement, but not sure how to make matlab look at both folders when a function needs data from both folder_new and folder_old.
Folder structure is via
year
->month
-->date
--->hour
---->min
댓글 수: 0
답변 (1개)
Benjamin Thompson
2022년 7월 1일
편집: Benjamin Thompson
2022년 7월 1일
You can get file dates using the "dir" function or keyword in MATLAB. Does any of this help?
>> D = dir
D =
105×1 struct array with fields:
name
folder
date
bytes
isdir
datenum
>> D(1).date
ans =
'17-Jun-2022 20:41:47'
>> datetime(D(1).date) > datetime(2020, 1, 1)
ans =
logical
1
>> datetime(D(1).date) > datetime(2022, 6, 18)
ans =
logical
0
댓글 수: 2
Benjamin Thompson
2022년 7월 1일
No this does not use a class in MATLAB. I showed an example here how to use the output of the dir command in MATLAB to compare a file date to some other date that you are interested in. Then based on whether the result is true or false you can use an "if" statement to move or copy it. If you find the MATLAB help article on "File Operations" you can see links to all the MATLAB functions that work on files. You probably want movefile or copyfile.
Now I was not very clear on what you were trying to do. If this is not helping you may want to add a simple example of what you are trying to do to this thread.
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!