find the difference of two structure elements

73 ビュー (過去 30 日間)
Max Bernstein
Max Bernstein 2015 年 7 月 23 日
回答済み: Max Bernstein 2015 年 7 月 23 日
Hello,
I'm trying to list files in a directory and categorize them. The files have the naming convention as follow:
Slow3C(20150721-1245).txt
Slow3CGO(20150721-1245).txt
Slow3CLMMax(20150721-1245).txt
Slow3CLMMin(20150721-1245).txt
Slow3CTC(20150721-1245).txt
Slow3CTrig(20150721-1245).txt
What I did is:
daq_files=dir('*(*).txt'); % all DAQ files
TCdaq_files=dir('*TC(*).txt'); % all TC files
GOdaq_files=dir('*GO(*).txt'); % all GO files
LMMindaq_files=dir('*LMMin(*).txt'); % all LMMin files
LMMaxdaq_files=dir('*LMMax(*).txt'); % all LMMax files
Trigdaq_files=dir('*Trig(*).txt'); % all Trig files
maindaq_files=
which gives a list of all the files, and put the filenames with TC, GO, etc.. in their own structure. I want the maindaq_files to be Slow3C(20150721-1245).txt, so I'm trying to figure out if I can find the difference between daq_files.name element and all the other variables'.name element, but I'm a little stuck. Is ther a way to do this?
Thanks!

採用された回答

Jos (10584)
Jos (10584) 2015 年 7 月 23 日
編集済み: Jos (10584) 2015 年 7 月 23 日
help setdiff
First put the names of the files into a cell array.
A = {daq_files.name} ;
B = {TCdaq_files.name} ;
Using the indices returned by setdiff you can select the elements from the original structure arrays returned by dir.
[~,ia,ib] = setdiff(A,B) ;
daq_files = daq_files(ia) ;
Something along these lines should work for you :-)

その他の回答 (3 件)

Jon
Jon 2015 年 7 月 23 日

Jon
Jon 2015 年 7 月 23 日

Max Bernstein
Max Bernstein 2015 年 7 月 23 日
Thanks Jos for your help, I figured it out using your hint. What I did was:
Alldaq_files=dir('*(*).txt'); % all DAQ files
TCdaq_files=dir('*TC(*).txt'); % all TC files
GOdaq_files=dir('*GO(*).txt'); % all GO files
LMMindaq_files=dir('*LMMin(*).txt'); % all LMMin files
LMMaxdaq_files=dir('*LMMax(*).txt'); % all LMMax files
Trigdaq_files=dir('*Trig(*).txt'); % all Trig files
All = [{TCdaq_files.name} {GOdaq_files.name} {LMMindaq_files.name} {LMMaxdaq_files.name} {Trigdaq_files.name}];
maindaq_files = setdiff({Alldaq_files.name},All, 'rows');
Jon I tried using what you suggested before but it wouldnt work because sometimes the filename changes so it's difficult to use a "constant" separator format such as \w-\w etc... Thanks a lot for your help though!

カテゴリ

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