Create a folder and save it with a field name

조회 수: 2 (최근 30일)
Daniel Boateng
Daniel Boateng 2019년 3월 12일
답변: dpb 2019년 3월 12일
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
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
Daniel Boateng 2019년 3월 12일
I am saving it in this folder. Sorry for the typo
Name_Project_folder = 'C:\PROJECTFILES\Projects';

댓글을 달려면 로그인하십시오.

답변 (2개)

dpb
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
Daniel Boateng 2019년 3월 12일
newfoldername=['newfolder_' DATA.Site];
mkdir(fullfile('C:\MicrogridDesignTool\Projects',newfoldername'))
the error message I get:
Error using fullfile (line 103)
Char inputs with multiple rows are not supported.
dpb
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
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.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by