フィルターのクリア

複数列を決まった列数毎に行列結合

7 ビュー (過去 30 日間)
かお
かお 2023 年 10 月 5 日
コメント済み: Dyuman Joshi 2023 年 10 月 5 日
1000行1列のdatファイルが200個(a01_1.dat,a01_2.dat,a01_3.dat,…,a01_10.dat,a02_1.dat,a02_2.dat,a02_3.dat,…,a02_10.dat,a03_1.dat,…)があります。
先に,ネームリストを作成して上記の()内のもの全てを読み込んではいます。
次に,各datファイルの最大値,最小値,平均値を統計し,これらを10個のdatファイル毎に1つのcsvファイルでまとめたいです。
一例として,csvファイル内は以下のような形式にしたいです。
Fname Max min Ave
a01_1.dat * * *
a01_2.dat * * *
… … … …
a01_10.dat * * *
アンサンブル平均 * * *
いいアイディアはございますでしょうか?
よろしくお願いいたします。

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 10 月 5 日
%Total number of files
num=200;
%Files in each group
len=10;
%Loop through each group
for k=1:num/len
%Preallocate arrays
[maxV,minV,avgV] = deal(zeros(len,1));
%Define the names of files
name = compose("a%02d_%d.dat",k,(1:len)');
%Read the files corresponding to group "k" via for loop
for m=1:len
arr=readmatrix(name(m));
%Generate the stats
maxV(m)=max(arr);
minV(m)=min(arr);
avgV(m)=mean(arr);
end
%Calculate 'Ensemble Average'
name(end+1) = "Ensemble Average";
maxV(end+1) = mean(maxV);
minV(end+1) = mean(minV);
avgV(end+1) = mean(avgV);
%Define a table
t=table(name,maxV,minV,avgV);
%Save the data in a csv file
writetable(t,sprintf('Data%d.csv',k))
end
  2 件のコメント
かお
かお 2023 年 10 月 5 日
Thank you so much!
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 5 日
You are welcome!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!