How to combine multiple .txt and calculate Mean, Std, Min, Max
3 ビュー (過去 30 日間)
古いコメントを表示
I have several .txt files like this
A .txt=
10 1 4
20 2 5
30 3 6
B.txt
10 7 11
20 8 12
30 9 13
C..txt
10 13 18
20 14 19
30 15 20
D.txt
10 1 4 7 11 13 18
20 2 5 8 12 14 19
30 3 6 9 13 15 20
I want to combine those file into once like in D.txt and plotting the files as first column is y ordinat [10,20,30] and others is x absis.
Then I want to calculate, mean , median, std and get max an min values of my file.
The Result like this
Mean Std Min Max
Y ordinat X absis
10 1 4 7 11 13 18 5 5.883795 -0.8838 10.8838
20 2 5 8 12 14 19 5 5.992058 -0.99206 10.99206
30 3 6 9 13 15 20 5 6.12178 -1.12178 11.12178
Any one can help? I would be appreciate.
Thanks you
Haifani
5 件のコメント
Turlough Hughes
2019 年 10 月 30 日
Ah, ok I see. min and max are the range of your solution from the mean by one standard deviation!
採用された回答
Turlough Hughes
2019 年 10 月 30 日
編集済み: Turlough Hughes
2019 年 10 月 30 日
Put all your txt files in a folder and you can then use the following
myfolder='name of the folder'
fils=dir([myfolder '\*.txt']); % lists all the files with a .txt extension in myfolder
[~,idx]=sort({fils.name}); % index to load .txt files alphabetically
temp=readmatrix([fils(idx(1)).folder '\' fils(idx(1)).name]); % read A.txt
Y=temp(:,1); X=temp(:,2:end);
for ii=idx(2:end)
temp=readmatrix([fils(ii).folder '\' fils(ii).name]);
X=[X temp(:,2:end)];
end
plot(X,Y)
As for your statistics you may need to modify mean and std to suit your needs:
meanD=mean(X,2); % these are the mean values of each row...
stdD=std(X,0,2); % standard deviations of each row.
medianD=median(X,2);
minD=meanD-stdD;
maxD=meanD+stdD;
D=table(Y,X,meanD,stdD,medianD,minD,maxD)
writetable(D,'D.txt')
D.txt will be saved in your working directory.
5 件のコメント
Turlough Hughes
2019 年 10 月 30 日
Yea, I wrote the above to allow flexibility in the number of files being loaded in, but you can also place the files in your working directory and load them in as follows:
A=readmatrix('A.txt');
B=readmatrix('B.txt');
C=readmatrix('C.txt');
X=[A(:,2:end) B(:,2:end) C(:,2:end)];
Y=A(:,1);
plot(X,Y)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Large Files and Big Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!