How to combine multiple .txt and calculate Mean, Std, Min, Max

2 visualizaciones (últimos 30 días)
Skydriver
Skydriver el 30 de Oct. de 2019
Editada: Skydriver el 31 de Oct. de 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 comentarios
Turlough Hughes
Turlough Hughes el 30 de Oct. de 2019
Ah, ok I see. min and max are the range of your solution from the mean by one standard deviation!
Skydriver
Skydriver el 30 de Oct. de 2019
Editada: Skydriver el 30 de Oct. de 2019
Yes. Off course So for developed the figure I only use one column of each as the y ordinat. Yes I also explained about standard deviation. But I still missing how to merge the data as displat in D.txt.

Iniciar sesión para comentar.

Respuesta aceptada

Turlough Hughes
Turlough Hughes el 30 de Oct. de 2019
Editada: Turlough Hughes el 30 de Oct. de 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 comentarios
Turlough Hughes
Turlough Hughes el 30 de Oct. de 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)
Skydriver
Skydriver el 31 de Oct. de 2019
Editada: Skydriver el 31 de Oct. de 2019
Nice its works know I change readmatrix with importdata. I use Matab2018a.
Thank you
Akhmad

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Large Files and Big Data en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by