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:
how to get a list aff the variable from all .mat files in a directory

Subject: how to get a list aff the variable from all .mat files in a directory

From: Olivier

Date: 13 Dec, 2012 19:34:08

Message: 1 of 4

Hello.
I'm new in using matlab.
I have a folder with a huge amount of .mat files (dataset form), and i'd like to get all the variables names from these files in a single column. How can i do that?

thank you very much

Subject: how to get a list aff the variable from all .mat files in a directory

From: Steven_Lord

Date: 13 Dec, 2012 22:57:08

Message: 2 of 4



"Olivier " <oliviercartapanis@yahoo.fr> wrote in message
news:kadajg$g44$1@newscl01ah.mathworks.com...
> Hello. I'm new in using matlab. I have a folder with a huge amount of .mat
> files (dataset form), and i'd like to get all the variables names from
> these files in a single column. How can i do that?

Combine DIR, ARRAYFUN or a FOR loop, and WHOS with the '-file' option.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: how to get a list aff the variable from all .mat files in a directory

From: Olivier

Date: 14 Dec, 2012 03:11:09

Message: 3 of 4

"Steven_Lord" <slord@mathworks.com> wrote in message <kadmg4$1ka$1@newscl01ah.mathworks.com>...
>
>
> "Olivier " <oliviercartapanis@yahoo.fr> wrote in message
> news:kadajg$g44$1@newscl01ah.mathworks.com...
> > Hello. I'm new in using matlab. I have a folder with a huge amount of .mat
> > files (dataset form), and i'd like to get all the variables names from
> > these files in a single column. How can i do that?
>
> Combine DIR, ARRAYFUN or a FOR loop, and WHOS with the '-file' option.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Thank you steve! However, i think my first question wasn t the good one. In fact, I d like to obtain a list of all the column names in all the files from a directory. I tried to use fieldnames, which obviously works for a loaded variable, but i need to do this for around 2000 .mat files, within a directory, and each files may contains 2 to tenth of columns, then to be able to save that list.
It might sounds simple but it still really complicated for me ( I began to use matlab 1 week ago, and I m not used to such kind of software).
Thank you for your help

Subject: how to get a list aff the variable from all .mat files in a directory

From: Steven_Lord

Date: 14 Dec, 2012 14:59:57

Message: 4 of 4



"Olivier " <oliviercartapanis@yahoo.fr> wrote in message
news:kae5cd$imh$1@newscl01ah.mathworks.com...
> "Steven_Lord" <slord@mathworks.com> wrote in message
> <kadmg4$1ka$1@newscl01ah.mathworks.com>...
>>
>>
>> "Olivier " <oliviercartapanis@yahoo.fr> wrote in message
>> news:kadajg$g44$1@newscl01ah.mathworks.com...
>> > Hello. I'm new in using matlab. I have a folder with a huge amount of
>> > .mat files (dataset form), and i'd like to get all the variables names
>> > from these files in a single column. How can i do that?
>>
>> Combine DIR, ARRAYFUN or a FOR loop, and WHOS with the '-file' option.
>>
>> --
>> Steve Lord
>> slord@mathworks.com
>> To contact Technical Support use the Contact Us link on
>> http://www.mathworks.com
>
> Thank you steve! However, i think my first question wasn t the good one.
> In fact, I d like to obtain a list of all the column names in all the
> files from a directory. I tried to use fieldnames, which obviously works
> for a loaded variable, but i need to do this for around 2000 .mat files,
> within a directory, and each files may contains 2 to tenth of columns,
> then to be able to save that list.
> It might sounds simple but it still really complicated for me ( I began to
> use matlab 1 week ago, and I m not used to such kind of software).
> Thank you for your help

DIR gives you the list of files in the directory.
WHOS with the '-file' option gives you the list of variables in a file.
Iterate over the list of files DIR gives you (using FOR) and use WHOS, then
store the results in the data structure that best fits the analysis you're
going to perform later on.

See the "Find Information in the Return Structure" example in the reference
page for DIR:

http://www.mathworks.com/help/matlab/ref/dir.html

and the third piece of code in the Examples for WHOS:

http://www.mathworks.com/help/matlab/ref/whos.html

Combined those get you most of the way to what you want.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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