about dlmwrite

2 views (last 30 days)
Cenk OZAN
Cenk OZAN on 20 Jul 2011
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?

Answers (1)

Fangjun Jiang
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.

Community Treasure Hunt

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

Start Hunting!