HOW CAN A .DAT FILE BE EDITED

Hi; I trying to change a certain number in a DAT file, the file consists of numbers and text as shown
The problem is every time I edit the file using commands like fprintf to overwrite the file, the external programme that supposes the read and executes the file gives me an error because it is not able to read the file anymore. please, is there a way to edit and save the file while it is still readable? Thanks

12 Comments

"is there a way to edit and save the file while it is still readable"
Of course this is possible. However you did not give us any details of the file specifications, or what you tried so far, so how do you expect us to help you?
Ahmed Abed
Ahmed Abed on 8 Jun 2017
Edited: dpb on 8 Jun 2017
Hi, thanks for your help and sorry about that. Before doing any coding with Matlab, I opened the DAT file using notepad++ and modified manually some data, then I run the external programme and it worked. then I tried to do the same thing with Matlab as following
delete('strain determination 01.DAT');
fileID = fopen('strain determination 01.DAT','w');
fprintf(fileID,'%s\n','1 (1) NPROB');
fprintf(fileID,'%s\n','pavement management system');
fprintf(fileID,'%s\n',' 1 0 1 1 (3) MATL NDAMA NPY NLG');
fprintf(fileID,'%s\n',' 0.001 (4) DEL');
fprintf(fileID,'%s\n',' 4 1 80 9 1 (5) NL NZ ICL NSTD NUNIT');
fprintf(fileID,'%s\n',' 5 25 25 (6) TH');
fprintf(fileID,'%s\n',' 0.35 0.35 0.35 0.35 (7) PR');
fprintf(fileID,'%s\n',' 5 (8) ZC');
fprintf(fileID,'%s\n',' (9) NBOND');
fprintf(fileID,'%s\n',' 6000000 1000000 150000 50000 (11) E');
fprintf(fileID,'%s\n',' 0 (13) LOAD');
fprintf(fileID,'%s\n',' 600 (14) CR CP');
fprintf(fileID,'%s\n',' (16) NR');
fprintf(fileID,'%s\n',' (17) RC');
fclose(fileID);
end
this is exactly what the external programme reads, however, it can not read the file created this way. I am not sure why. please, is there any way to fix this situation? thanks
You can try
fileID = fopen('strain determination 01.DAT','wt');
if it has to do with what the external program expects for EOL marks.
What we really need is to see a copy of the actual text file itself that is successfully read, NOT how it's displayed.
Hi, I tried 'wt' instead of 'w' and it worked. I just needed to cancel delete command as well. thank you so much for your help
@Ahmed Abed: please edit your question and upload a copy of the file by clicking the paperclip button.
Hi, I could not upload the file because its format is unsupported. if you like sent me your email address by a message so I can email you the file.
Stephen23
Stephen23 on 9 Jun 2017
Edited: Stephen23 on 9 Jun 2017
Ahmed Abed: just add .txt to the file extension. For example change .xls to .xls.txt. Then edit your question and upload the file by clicking the paperclip button.
Stephen: I tried to change the extension even though it was not uploaded and even tried to compress the file but it did not work as well.
Both zip and txt files are supported by this forum, so if you change the extension to .txt it should be able to be uploaded. What size is the file? Do you get an error or warning? What browser are you using?
Thats the error I am getting when uploading the file. the file size is 291 bytes, I changed the extension still not working, I am using google chrome.
Jan
Jan on 9 Jun 2017
Edited: Jan on 9 Jun 2017
As we see in this screenshot, you try to attach a .rar file. The error message tells clearly, that this is not supported, but a .zip file would work and .txt files also.
Nevertheless, your problem is solved and attaching the file is not needed anymore.
Instead of using 'wt' in fopen, you can replace the line breaks also by '\r\n'. Beside the Editor shipped with Windows, your application seems to require the DOS linebreaks. What a pitty.
Sorry, I did not notice that, the file is uploaded now. Yes, the problem is solved and thanks for your support!

Sign in to comment.

Answers (0)

Categories

Asked:

on 8 Jun 2017

Commented:

on 9 Jun 2017

Community Treasure Hunt

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

Start Hunting!