Simply Directory Question

9 ビュー (過去 30 日間)
B_Richardson
B_Richardson 2011 年 8 月 4 日
Hello All,
Quick question, I am trying to load all files from a folder that have a .m ext:
folder = C:\Users\ecorbett\Documents\MATLAB\UI\VCoachData\0005_Capture_10072009\AccelData
files = dir(folder)
I know I need to include something like '*.m' in dir but I dont know the correct syntax to do so. Can someone help me with this?

採用された回答

Paulo Silva
Paulo Silva 2011 年 8 月 4 日
m=dir([folder '\*.m']);
files=arrayfun(@(x)m(x).name,1:numel(m),'uni',false); %or use Oleg suggestion
  9 件のコメント
Walter Roberson
Walter Roberson 2011 年 8 月 4 日
Think I'd be able to get Tenure? ;-)
B_Richardson
B_Richardson 2011 年 8 月 4 日
You'd have my vote!

サインインしてコメントする。

その他の回答 (2 件)

B_Richardson
B_Richardson 2011 年 8 月 5 日
Hey guys, I'm still having trouble with this code. I've included the some more to give you a better understanding of what I'm tring to do.
I just want to get a dir (load .mat data files only) and loop through that dir until I match my pattern. Once I match, load construct fullfile.
[pathstr, name, ext] = fileparts(file)
name = 'AccelData';
file2 = fullfile(pathstr,[name])
z=dir([file2 '\*.m']);
files = {z.name}
Pattern=itemselected(1:9)
for i = 1 : numel(files)
value=files(i).name;
if strfind(value,Pattern)
f = fullfile(file2,value)
For some reason,
z=dir([file2 '\*.m']);
files = {z.name}
files is coming up empty. The way I had it before worked:
files = dir(folder)
But of course it included all file types and i just want the matlab data files.
  4 件のコメント
B_Richardson
B_Richardson 2011 年 8 月 5 日
0x1 struct array with fields:
name
date
bytes
isdir
datenum
Oleg Komarov
Oleg Komarov 2011 年 8 月 5 日
can you show what's file2?

サインインしてコメントする。


B_Richardson
B_Richardson 2011 年 8 月 5 日
I feel so stupid right now! My files are .mat not .m! AARRRGGGGGG Thanks everybody!!

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by