Create a folder and save it with a field name
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a matlab structure called DATA and in this structure I have a field Site and value entry
I want to create a folder Called newfolder_entry. Where Site is a field in the matlab structure.
Please how do I do this.
Name_Project_folder = [C:\PROJECTFILES\Code'\..\Projects'];
cd(Name_Project_folder)
mkdir([Name_Project_folder '\newfolder_DATA.Site'])
2 comentarios
Geoff Hayes
el 12 de Mzo. de 2019
Daniel - which folder are you trying to save the data into? You have
Name_Project_folder = [C:\PROJECTFILES\Code'\..\Projects'];
but I'm not sure if you intend it to be the above (missing single quotes) or something like
Name_Project_folder = 'C:\PROJECTFILES\Code\..\Projects';
or
Name_Project_folder = 'C:\PROJECTFILES\Projects';
Respuestas (2)
dpb
el 12 de Mzo. de 2019
Would be easier to see the actual struct via
whos DATA
to ensure we follow the actual construction, but basically if Data.Site returns a char() string 'Entry' then
newfoldername=['newfolder_' DATA.Site];
mkdir(fullfile(Name_Project_folder,newfoldername) )
The above is, of course, subject to many possible errors in interpretation of what you really have and what you intend...but it's a first guess from what we have been given.
8 comentarios
dpb
el 12 de Mzo. de 2019
As far as the message goes regarding missing arguments, we would need to see the result of the fullfile() call for the newdir parameter in order to know if that form is what is triggering the need for the optional parendir parameter.
That would also entail knowing the current working directory at the time you're trying to execute the call...
dpb
el 12 de Mzo. de 2019
>> newfoldername=['newfolder_' DATA.Site];
mkdir(fullfile('C:\MicrogridDesignTool\Projects',newfoldername'))
Error using fullfile (line 90)
Char inputs with multiple rows are not supported.
>> newfoldername
newfoldername =
'newfolder_entry'
>> newfoldername'
ans =
15×1 char array
'n'
'e'
'w'
'f'
'o'
'l'
'd'
'e'
'r'
'_'
'e'
'n'
't'
'r'
'y'
>>
You've got an extra quote at the end of variable newfoldername that transforms it to a column vector...get rid of that.
> (fullfile('C:\MicrogridDesignTool\Projects',newfoldername))
ans =
'C:\MicrogridDesignTool\Projects\newfolder_entry'
>> mkdir(fullfile('C:\MicrogridDesignTool\Projects',newfoldername))
>> dir c:\MicrogridDesignTool\Projects\newfolder_entry\
. ..
>>
Doing that here and it works as advertised...
MORAL: Debug your work carefully and look at what intermediates produce to see why results aren't as expected.
0 comentarios
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!