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.

回答 (1 件)

KSSV
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
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.
Mahrukh Farooq
Mahrukh Farooq 2016 年 11 月 28 日
there are 366 files in a folder each having 1440 rows, X should take median of 60 rows of last 4 columns making 24 rows for each file

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

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by