How to combine multiple .txt and calculate Mean, Std, Min, Max
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Skydriver
le 30 Oct 2019
Modifié(e) : Skydriver
le 31 Oct 2019
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 commentaires
Turlough Hughes
le 30 Oct 2019
Ah, ok I see. min and max are the range of your solution from the mean by one standard deviation!
Réponse acceptée
Turlough Hughes
le 30 Oct 2019
Modifié(e) : Turlough Hughes
le 30 Oct 2019
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 commentaires
Turlough Hughes
le 30 Oct 2019
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)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Large Files and Big Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!