Thread Subject: how to creat directory name

Subject: how to creat directory name

From: chaosheng

Date: 22 Oct, 2009 23:19:22

Message: 1 of 3

hi guys,
I faced a problem about creating a directory and saving figures in it. and I need the directory name which changes with my input values N. I did this as follows, but it doesn't work.


N = 10;
directoryName = sprintf('%dGammaFigure',N);
if ~exist(directoryName,'dir')
    mkdir(directoryName)
end
paths=[pwd,'\directoryName\'];% problem comes here,directoryName is not 10GammaFigure but is directoryName itself

x = 0:0.01:1;
y = exp(x);

plot(y,x);
set(gcf,'PaperPositionMode','auto');
print('-djpeg', [paths,'figure.jpg']);

Please help me to solve it. thanks

Subject: how to creat directory name

From: Nasser M. Abbasi

Date: 22 Oct, 2009 23:40:26

Message: 2 of 3


"chaosheng " <csudeng@126.com> wrote in message
news:hbqp9q$ch4$1@fred.mathworks.com...
> hi guys,
> I faced a problem about creating a directory and saving figures in it. and
> I need the directory name which changes with my input values N. I did this
> as follows, but it doesn't work.
>
>
> N = 10;
> directoryName = sprintf('%dGammaFigure',N);
> if ~exist(directoryName,'dir')
> mkdir(directoryName)
> end
> paths=[pwd,'\directoryName\'];% problem comes here,directoryName is not
> 10GammaFigure but is directoryName itself
>

This does not make much sense. You created a variable called, say z, and
then you expect this variable to have its original value when you typed it
inside a string as in `\z\` ??

Why not simply create the directory name with those slashes on it in the
first place?

EDU>> N=10; directoryName = sprintf('\\%dGammaFigure\\',N);
EDU>> paths=[pwd,directoryName]

paths =

C:\Documents and Settings\Owner\My Documents\MATLAB\10GammaFigure\


--Nasser

Subject: how to creat directory name

From: chaosheng

Date: 23 Oct, 2009 02:24:01

Message: 3 of 3

"Nasser M. Abbasi" <nma@12000.org> wrote in message <M36Em.13534$pl1.2458@newsfe01.iad>...
>
> "chaosheng " <csudeng@126.com> wrote in message
> news:hbqp9q$ch4$1@fred.mathworks.com...
> > hi guys,
> > I faced a problem about creating a directory and saving figures in it. and
> > I need the directory name which changes with my input values N. I did this
> > as follows, but it doesn't work.
> >
> >
> > N = 10;
> > directoryName = sprintf('%dGammaFigure',N);
> > if ~exist(directoryName,'dir')
> > mkdir(directoryName)
> > end
> > paths=[pwd,'\directoryName\'];% problem comes here,directoryName is not
> > 10GammaFigure but is directoryName itself
> >
>
> This does not make much sense. You created a variable called, say z, and
> then you expect this variable to have its original value when you typed it
> inside a string as in `\z\` ??
>
> Why not simply create the directory name with those slashes on it in the
> first place?
>
> EDU>> N=10; directoryName = sprintf('\\%dGammaFigure\\',N);
> EDU>> paths=[pwd,directoryName]
>
> paths =
>
> C:\Documents and Settings\Owner\My Documents\MATLAB\10GammaFigure\
>
>
> --Nasser
>
Thank you very much. I got it.
chaosheng

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com