필터 지우기
필터 지우기

Combining .txt files and averaging data

조회 수: 1 (최근 30일)
Sophia
Sophia 2022년 2월 13일
답변: Rik 2022년 2월 13일
I have multiple .txt files with the same type of data that I would like to merge
The first column is the same for each .txt file so I need to add the second column of the second .txt to the first .txt
I would also like to average the data of column 3 and 4 in the merged file for each row
Thanks in advance :)
  댓글 수: 2
Rik
Rik 2022년 2월 13일
That seems easy to do. What have you tried?
Sophia
Sophia 2022년 2월 13일
I've looked extensively online but haven't been able to find a solution

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

답변 (1개)

Rik
Rik 2022년 2월 13일
You can get my readfile function from the FEX. If you are using R2017a or later, you can also get it through the AddOn-manager.
With that function you can read your file to a cell array (1 line per element).
Then you need to determine where your data starts.
Then you concatenate the data you want to put on 1 line.
Lastly, you can write the new file with fprintf:
fid=fopen(filename,'w');
fprintf(fid,'%s\n',cellstr_with_data{:});
fclose(fid);

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by