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

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';
I am saving it in this folder. Sorry for the typo
Name_Project_folder = 'C:\PROJECTFILES\Projects';

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

답변 (2개)

dpb
dpb 2019년 3월 12일

0 개 추천

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일
편집: Guillaume 2019년 3월 12일
I tried
newfoldername=['newfolder_' DATA.Site];
but it throws an error
'Not enough input arguments'
Guillaume
Guillaume 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
dpb 2019년 3월 12일
Not to mention we still haven't seen the actual definiton of the struct in question here...
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
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
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...
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일

0 개 추천

>> 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.

카테고리

태그

질문:

2019년 3월 12일

답변:

dpb
2019년 3월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by