- What is the question?
- Where is the data?
- What is the problem?
help with writing code for data post processing
조회 수: 13 (최근 30일)
이전 댓글 표시
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!