Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Directory Name

Subject: Directory Name

From: Izaskun Azk

Date: 1 Nov, 2008 10:29:01

Message: 1 of 8

Hi!
I have a problem with saving a .mat file. I have to save it with the name of the directory in which the .mat file ist. For example:
Directory name: PLL_123
.mat file name:PLL_123.mat

I don?t know how could i have the directory name, because the sentence like pwd,or fileparts ... returns the name of the full path.

Can anyone helps me?
Thanks!

Subject: Directory Name

From: Md learn

Date: 1 Nov, 2008 13:40:20

Message: 2 of 8

try this,
1)get the current directory path using 'cd' command
2)split the path by the delimiter '\' using, var=strsplit(cd,'\') , which can be download form file exchange
3)find ,len_var=length(var)
4) find ,max_len=max(len_var);
5) use, save([var(max_len),'.mat']);

Subject: Directory Name

From: Praetorian

Date: 1 Nov, 2008 14:15:06

Message: 3 of 8

On Nov 1, 4:29=A0am, "Izaskun Azk" <izaskunazkar...@gmail.com> wrote:
> Hi!
> I have a problem with saving a .mat file. I have to save it with the name=
 of the directory in which the .mat file ist. For example:
> Directory name: PLL_123
> .mat file name:PLL_123.mat
>
> I don?t know how could i have the directory name, because the sentence li=
ke pwd,or fileparts ... returns the name of the full path.
>
> Can anyone helps me?
> Thanks!

You're on the right track. Use 'pwd' to get the current directory
path. Use the 2 (or more) output version of 'fileparts' to get just
directory name.

Subject: Directory Name

From: John D'Errico

Date: 1 Nov, 2008 14:23:02

Message: 4 of 8

"Md learn" <ashik1986@lycos.com> wrote in message <gehm84$q2o$1@fred.mathworks.com>...
> try this,
> 1)get the current directory path using 'cd' command
> 2)split the path by the delimiter '\' using, var=strsplit(cd,'\') , which can be download form file exchange
> 3)find ,len_var=length(var)
> 4) find ,max_len=max(len_var);
> 5) use, save([var(max_len),'.mat']);

By the way, rather than assume \ as the delimiter, if
you will ever worry about OS changes or running on a
different OS, it will be better to use filesep.

John

Subject: Directory Name

From: Md learn

Date: 1 Nov, 2008 14:35:03

Message: 5 of 8

the strsplit fuction can be downloaded from,
http://www.mathworks.com/matlabcentral/fileexchange/4615

Subject: Directory Name

From: Izaskun Azk

Date: 1 Nov, 2008 14:51:01

Message: 6 of 8

Praetorian <ashish.sadanandan@gmail.com> wrote in message <ef1ad7e1-9283-4892-84e7-3e2127f74d41@f40g2000pri.googlegroups.com>...
> On Nov 1, 4:29=A0am, "Izaskun Azk" <izaskunazkar...@gmail.com> wrote:
> > Hi!
> > I have a problem with saving a .mat file. I have to save it with the name=
> of the directory in which the .mat file ist. For example:
> > Directory name: PLL_123
> > .mat file name:PLL_123.mat
> >
> > I don?t know how could i have the directory name, because the sentence li=
> ke pwd,or fileparts ... returns the name of the full path.
> >
> > Can anyone helps me?
> > Thanks!
>
> You're on the right track. Use 'pwd' to get the current directory
> path. Use the 2 (or more) output version of 'fileparts' to get just
> directory name.

ok, but i don?t know what do you mean when you said that there are 2 or more output version of fileparts. where could i find them?
Thanks!

Subject: Directory Name

From: Izaskun Azk

Date: 1 Nov, 2008 14:52:02

Message: 7 of 8

"Md learn" <ashik1986@lycos.com> wrote in message <gehm84$q2o$1@fred.mathworks.com>...
> try this,
> 1)get the current directory path using 'cd' command
> 2)split the path by the delimiter '\' using, var=strsplit(cd,'\') , which can be download form file exchange
> 3)find ,len_var=length(var)
> 4) find ,max_len=max(len_var);
> 5) use, save([var(max_len),'.mat']);

Thank you! i will try it now.

Subject: Directory Name

From: Praetorian

Date: 1 Nov, 2008 18:12:41

Message: 8 of 8

On Nov 1, 8:51=A0am, "Izaskun Azk" <izaskunazkar...@gmail.com> wrote:
> Praetorian <ashish.sadanan...@gmail.com> wrote in message <ef1ad7e1-9283-=
4892-84e7-3e2127f74...@f40g2000pri.googlegroups.com>...
> > On Nov 1, 4:29=3DA0am, "Izaskun Azk" <izaskunazkar...@gmail.com> wrote:
> > > Hi!
> > > I have a problem with saving a .mat file. I have to save it with the =
name=3D
> > =A0of the directory in which the .mat file ist. For example:
> > > Directory name: PLL_123
> > > .mat file name:PLL_123.mat
>
> > > I don?t know how could i have the directory name, because the sentenc=
e li=3D
> > ke pwd,or fileparts ... returns the name of the full path.
>
> > > Can anyone helps me?
> > > Thanks!
>
> > You're on the right track. Use 'pwd' to get the current directory
> > path. Use the 2 (or more) output version of 'fileparts' to get just
> > directory name.
>
> ok, but i don?t know what do you mean when you said that there are 2 or m=
ore output version of fileparts. where could i find them?
> Thanks!

Read the help for fileparts. Also, if you're using R2008a, or maybe
even R2007b, you don't need the strsplit function from the file
exchange. regexp has a split option which does what you want. And as
John mentioned, use filesep instead of the '/' or '\' character.

Tags for this Thread

No tags are associated with this thread.

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.

Contact us