about dlmwrite
2 views (last 30 days)
Show older comments
I have a text file which consists of numbers (for example myfile.txt=[1 2 3;4 5 6; 7 8 9]. I want to replace its "5 6 8 9" elements with new matrix (for example A=[3 2;4 1]). Other elements in myfile.text must be same. I tried it with dlmwrite, dlmwrite ('myfile.txt',A,' ',1,2), but other elements was deleted. How can I change only these elements without deleting other elements?
0 Comments
Answers (1)
Fangjun Jiang
on 20 Jul 2011
DLMWRITE('FILENAME',M,'DLM',R,C) writes matrix M starting at offset row R, and offset column C in the file. But it will completely over-write the existing file anyway. It just leaves some delimiter to make the offset. It's not going to open the old file, find the offset and just over-write the new data.
You'll have to read in the whole data, do the proper replacement in MATLAB and then write it back.
0 Comments
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!