I want to read all the text files from a folder deleting headers and some string columns and calculate the median of some selected rows
2 ビュー (過去 30 日間)
古いコメントを表示
I am able to do it for single file(.min). Here is the code. Each file contains 1440 rows and have to take median of 60 rows of last 4 columns.
M=dlmread('myfile.min','',23,2);
for i=1:24;
mat=(M((i*60)-59:i*60,2:5));
X(i,2:5)=median(M((i*60)-59:i*60,2:5));
end
X(:,1)=[];
how I can do it for all the files in the folder? attached are 2 sample files.
0 件のコメント
回答 (1 件)
KSSV
2016 年 11 月 24 日
編集済み: KSSV
2016 年 11 月 24 日
F = dir('*.txt');
N = length(F) ; % total files
for ii = 1:N % loop for each file
file = F(ii).name ;
%%do what you want
end
3 件のコメント
KSSV
2016 年 11 月 28 日
Try this:
for k=1:length(fnames);
fname = fnames(k).name;
tradataa{k} = dlmread(fname,'',23,2);
for i=1:24;
mat=(tradataa{k}((i*60)-59:i*60,2:5));
XX(i,2:5)=median(tradataa{k}((i*60)-59:i*60,2:5));
end
X(k,:)=XX;%to delete all rows of 1st column
end
I can initialize XX and X if I know size of XX.
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!