make use of dynamic mkdir

Hi
How do I make use of mkdir so that its value changes?
I have data from 2015 to 2022. I have analysed the data and now need to save the data monthly for each year. So, I am trying to create a parent folder for saving the years. Indise each parent folder, I want to have a monthly folder.

 Accepted Answer

Use the function form of mkdir rather than the command form.
cd(tempdir)
mkdir 1985379 % command form, creating a place for use to write in
cd 1985379
dir % show that the directory is empty
. ..
month = "June";
year = 2023;
newfoldername = month + year
newfoldername = "June2023"
mkdir(newfoldername) % function form
dir % directory is no longer empty
. .. June2023

4 Comments

Thanks!
A part of the code that I have written is mentioned below.
If I use the cd command for mkdir, will it not affect the 'files' structure?
cd 'C:\ParentDirectory'
P = pwd;
files = dir(fullfile(P, "*", '*', '*.csv'));
filenames = fullfile({files.folder}, {files.name});
num_files = length(files);
Avoid CD in code. Avoid changing directories just to access data files. Better:
P = 'C:\ParentDirectory'
files = dir(fullfile(P, "*", '*', '*.csv'));
...
and now need to save the data monthly for each year
It is not obvious to me how the monthly data for each year is being represented. You currently only summarize by hour within each file; you have no code at present to summarize by day or month.
Thanks!

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 19 Jun 2023

Commented:

on 20 Jun 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!