Filter löschen
Filter löschen

Create a subfolder with datetime as its name using mkdir

38 Ansichten (letzte 30 Tage)
Moritz Pohl
Moritz Pohl am 27 Feb. 2018
Bearbeitet: NISARGA G K am 8 Mär. 2018
Hello folks,
I currently try to create a subfolder in my 'Results' folder which shall be named after the time and date the program was used. So far, this is what I have:
currDate = strrep(datestr(datetime), ' ', '_');
mkdir Results currDate
The problem is that mkdir does not recognize currDate as a char vector. So the created folder is named 'currDate' and not '27-Feb-2018_...'. Can anyone help me out?
Cheers

Antworten (1)

NISARGA G K
NISARGA G K am 8 Mär. 2018
Bearbeitet: NISARGA G K am 8 Mär. 2018
Hi Moritz
I understand that, you want to create a subfolder with the time and date the program was used as name of the subfolder. 1)Colon is a reserved character and cannot be used in naming the folder. 2)Use function syntax than command syntax while passing variable to 'mkdir'. The following link would help you in understanding better:
https://www.mathworks.com/help/matlab/matlab_prog/command-vs-function-syntax.html
The below code snippet would serve the purpose:
currDate = strrep(datestr(datetime), ':', '_');
mkdir('Results',currDate)

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by