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

조회 수: 1 (최근 30일)
Skydriver
Skydriver 2019년 10월 30일
편집: Skydriver 2019년 10월 31일
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
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!
Skydriver
Skydriver 2019년 10월 30일
편집: Skydriver 2019년 10월 30일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Turlough Hughes
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
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)
Skydriver
Skydriver 2019년 10월 31일
편집: Skydriver 2019년 10월 31일
Nice its works know I change readmatrix with importdata. I use Matab2018a.
Thank you
Akhmad

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile 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!

Translated by