How to make matlab access two folders for data when separated by date
1 ビュー (過去 30 日間)
Emily 2022 年 7 月 1 日
コメント済み: Benjamin Thompson 2022 年 7 月 1 日
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
回答 (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
105×1 struct array with fields:
>> datetime(D(1).date) > datetime(2020, 1, 1)
>> datetime(D(1).date) > datetime(2022, 6, 18)
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.
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!