How can I filter multiple files ?

7 ビュー (過去 30 日間)
maadi
maadi 2011 年 3 月 11 日
I have made a filter as following
[b,a] = butter(9,.02,'low'); x=textread('noisy.out'); y=filter(b,a,x); save filtered.out y -ASCII
I have 1000 files and I would like to filter all my files using the above filter. Is there any way that I can do this efficiently? my files are named like 1.out 2.out , ... 1000.out
any suggestion would be appreciated.
my *.out files just include one column with numbers
this is one example -4.034E+02 -4.007E+02 -3.987E+02 -3.978E+02
All numbers in one column and each file contains 13000 numbers

採用された回答

Oleg Komarov
Oleg Komarov 2011 年 3 月 11 日
Parse the folder for existing 1-1000.out files and import them one-by-one apply filter and save:
% Retrieve all the files in a directory
names = dir('C:\Users\Oleg\Desktop\Nuova cartella');
names = {names(~[names.isdir]).name};
% Select only the files #.out
idx = ~cellfun('isempty',regexp(names,'\d+\.out'));
names = names(idx);
% Filter
[b,a] = butter(9,.02,'low');
for n = names
% Open file for reading
fid = fopen([myDir n{:}],'r');
x = textscan(fid,'%f');
y = filter(b,a,cat(1,x{:}));
% Discard content and write filtered data
fid = fopen([myDir n{:}],'w');
fprintf(fid,'%E\r\n',y);
fid = fclose(fid);
end
Oleg
  12 件のコメント
Oleg Komarov
Oleg Komarov 2011 年 3 月 12 日
Ok I modified the script accordingly. Be careful: the content is imported, filtered and overwritten. Make some test files.
maadi
maadi 2011 年 3 月 13 日
Thank you Oleg I really appreciate that

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFilter Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by