Why does dir('*.mat') not list all of the .mat files in directory?
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
更多回答(1 个)
Azzi Abdelmalek
2012-8-21
编辑:Azzi Abdelmalek
2012-9-1
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 个评论
Jan
2012-8-22
~cellfun('isempty', d3) is faster than ~cellfun(@isempty, d3), which is faster than cellfun(@(x) ~isempty(x)).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!