add column to file with dlmwrite
이전 댓글 표시
Hello, is there anyway to add a column to an existing file using dlmwrite?
I've tried to transpose it to add lines instead and later convert it to columns again but I get the error " FILENAME must be a character vector "
A = [0.23;0.44;0.65;0.12];
A = A';
oldfile = dlmread('testfile1.txt');
oldfile = oldfile';
dlmwrite(oldfile,A,'-append','newline','pc','delimiter',' ')
댓글 수: 1
Star Strider
2019년 4월 5일
Reference: Write column in .txt file
답변 (1개)
Walter Roberson
2019년 4월 5일
0 개 추천
Only by rewriting the entire file.
댓글 수: 4
Marisabel Gonzalez
2019년 4월 5일
Walter Roberson
2019년 4월 5일
oldfile = dlmread('testfile1.txt');
A = [0.23; 0.44; 0.65; 0.12];
oldfile(1:length(A), end+1) = A; %done this way in case the rows are not the same
dlmwrite('testfile1.txt', oldfile, 'newline', 'pc', 'delimeter', ' ');
Devikrishna
2023년 1월 12일
My matrix is in the form 39×39 I want to add a column using dlmwrite and make 39× 40
Walter Roberson
2023년 1월 12일
The way that text files are designed in Windows, Mac, and Linux makes it impossible to add additional information to a row without rewriting the entire file. That applies not just to dlmwrite but also to writematrix and to using excel.
You need to use a system like I posted the code for, of reading the existing file, adding the new column in memory, and writing out the revised content
카테고리
도움말 센터 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!