Create a folder and save it with a field name
古いコメントを表示
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';
Daniel Boateng
2019 年 3 月 12 日
回答 (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 件のコメント
Daniel Boateng
2019 年 3 月 12 日
編集済み: Guillaume
2019 年 3 月 12 日
The only reason the line
newfoldername=['newfolder_' DATA.Site];
could throw a not enough input argument error is if that line is in a function, that specify DATA as an input and if you've called that function without giving it that DATA input.
Or of course, it could be that it (which throws the error) is actually another line.
Either way, we've left to guess the problem since you haven't provided enough information.
When you get an error, give us the full text of the error message, everything in red.
dpb
2019 年 3 月 12 日
Not to mention we still haven't seen the actual definiton of the struct in question here...
Geoff Hayes
2019 年 3 月 12 日
Daniel's answer moved here

This is the struct DATA and with different fields. I have a matlab struct called DATA and in this struct 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.
When I do this I get an error:
newfoldername=['newfolder_' DATA.Site];
mkdir(fullfile(Name_Project_folder,newfoldername) )
Please can anyone be of help. Thanks
Geoff Hayes
2019 年 3 月 12 日
Daniel - can you copy and paste the full error message? Also, please use the comment section to further the dialog (rather than creating "answers").
dpb
2019 年 3 月 12 日
And, Daniel, I can't read the image nor can anybody do anything with an image...cut and paste text from the command line...
Daniel Boateng
2019 年 3 月 12 日
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.
カテゴリ
ヘルプ センター および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!