help with writing code for data post processing

조회 수: 13 (최근 30일)
Chelsea Fontaine
Chelsea Fontaine 2019년 11월 9일
댓글: darova 2019년 11월 9일
Hi,
I have many data txt files that gives values of interest at different time steps (in order from start to finish). I am going to vary one parameter to change the initial conditions for each of the different run. My problem is that I want to take the same data in each file (at the same time step) compute the average of a given parameter at a given time step for each of the N files I generate (once I am able to do this I am going to plot the average(s) to reduce the overall noise in the data that I've been getting from just a single run). Therefore, I essentially want to make a final text file called averages.txt that I can use to plot the averages.
this is what I have so far.
PathStr = 'C:\data\';
textFiles = dir([PathStr '*.txt'])
fileID = fopen('averages.txt', 'w')
%r = # of rows per file, c = # columns per file
r = % depends on files type
c = % depends on files type
MyData = zeros(r, c, length(textFiles));
Average = zeros(r, c);
for k = 1:length(textFiles)
textFilename = ['data' num2str(k) '.txt'];
fid = fopen(textFilename, 'rt'); %Open text file, 'rt' = read text file
Data = textscan(fid,'%d %d %d %d %d %d\n', 'Delimiter',' ', c); %Read file into c seperate variables
for a = 1:r
for b = 1:c
Average(a,b) = Average(a,b) + MyData(a,b,:);
end
end
Average(:,:) = Average(:,:)/length(textFiles);
fclose(fid);
end
save('averages.txt', 'Average(r,c)', '-ascii', '-double', '-tabs')
  댓글 수: 1
darova
darova 2019년 11월 9일
  • What is the question?
  • Where is the data?
  • What is the problem?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by