Create a folder and save it with a field name
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Geoff Hayes
2019-3-12
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';
回答(2 个)
dpb
2019-3-12
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 个评论
dpb
2019-3-12
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
2019-3-12
>> 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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!