Filter löschen
Filter löschen

Why does dir('*.mat') not list all of the .mat files in directory?

1 Ansicht (letzte 30 Tage)
Dan
Dan am 21 Aug. 2012
Hello,
I'm trying to create a structure file which lists all of the .mat files in my directory:
files = dir('*.mat')
This code returns a 4x1 structure, but I have 8 .mat files in the directory. All 8 of the .mat files are the same format (i.e. 3 variables per .mat file). Can anyone tell me why my other .mat files are not being listed in the struct file?
Thanks, Dan

Akzeptierte Antwort

Matt Fig
Matt Fig am 21 Aug. 2012
Bearbeitet: Matt Fig am 21 Aug. 2012
Are you sure about those files being in there? Does WHAT see them (type: what) in there?
D = dir;
length(regexp([D(:).name],'\.mat')) % What does this say
  6 Kommentare
Dan
Dan am 21 Aug. 2012
Matt, your example above works just fine...now its just bugging me why DIR isn't working.
Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 21 Aug. 2012
Bearbeitet: Azzi Abdelmalek am 1 Sep. 2012
try this
d=dir
d1=struct2cell(d);
d2=d1(1,:);
d3=cellfun(@(x) regexp(x,'.mat'),d2,'uni',false)
d4=find(~cellfun('isempty', d3))
files=d2(d4)'
  3 Kommentare
Jan
Jan am 22 Aug. 2012
~cellfun('isempty', d3) is faster than ~cellfun(@isempty, d3), which is faster than cellfun(@(x) ~isempty(x)).
Azzi Abdelmalek
Azzi Abdelmalek am 1 Sep. 2012
thanks Simon, did'nt read your comment until now.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by