Modify Text File Data in MATLAB
조회 수: 2 (최근 30일)
이전 댓글 표시
Dear Members,
I have the following text file which I want to manipulate. Currently the data looks like this:
Set-1,2E-01,13.23,93.90,49,-9,0,0,20,33,74,-9,0,0
Set-2,2.21E-01,19,194,39,1,0,0,-19.7823,28.9842,78.3404,-7,0,0
I want to change it to the following format (Note- The last 6 numbers are now placed on the next line and no comma at end of first line):
Set-1,2E-01,13.23,93.90,49,-9,0,0
20,33,74,-9,0,0
Set-2,2.21E-01,19,194,39,1,0,0
-19.7823,28.9842,78.3404,-7,0,0
Could you please show me how this can be done in Matlab.
댓글 수: 0
채택된 답변
Jan
2017년 8월 2일
S = fileread('example.txt');
C = strsplit(S, '\n');
for iC = 1:numel(C)
aC = C{iC};
comma = strfind(aC, ',');
aC(comma(end - 5)) = char(10);
C{iC} = aC;
end
fid = fopen('Output.txt', 'w');
if fid == -1, error('Cannot open file for writing'); end
fprintf(fid, '%s\n', C{:});
fclose(fid);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Standard File Formats에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!