Open file in notepad, save file as *.txt, and close notepad
Afficher commentaires plus anciens
Hello,
I have an ASCII file format *.mca that is not recognized by Matlab. I know that I can open the files from the Matlab comand line with " !notepad Filename.mca". Is there a way to then save each file as a *.txt and close notepad. Ideally I would run a script with an input of some directery that has all of the *.mca files and then run a loop to save all the files as *.txt .
4 commentaires
Mohammad Sami
le 18 Juin 2020
can you describe what you want to do with files. you can programmatically read the files without changing the extensions.
Mohammad Sami
le 18 Juin 2020
To rename files, you can use the movefile function to move / rename the files, without opening the files.
Stephen23
le 18 Juin 2020
This question seems to be based on the misunderstanding that changing the file extension will change MATLAB's ability to interpret some specific text file format. It won't: changing the file extension will not mean that MATLAB can suddenly interpret the file format.
Iny any case, MATLAB can open any text file using fopen, the extension does not have to be .txt. You can open .mca files just like any other text file:
fid = fopen('filename.mca','rt');
...
fclose(fid);
Walter Roberson
le 18 Juin 2020
Opening in notepad and saving can have effects on newline line endings -- but MATLAB can handle both standards. Sometimes you might need to fopen() with 'rt' instead 'r' for some programs.
Opening in notepad and saving can have effects on character set encoding. R2020a onward can automatically handle UTF8 and UTF16. However, MATLAB will not necessarily automatically detect CP-1252 encoding. It is possible to get MATLAB to read CP-1252, and sometimes that is easy, and sometimes it takes a bit more work (depending how the file is being processed.)
Réponses (1)
Image Analyst
le 18 Juin 2020
0 votes
If you want to do it manually, then do it manually in notepad. User manually changes text on a whim and manually saves it from the pulldown menu. No need for MATLAB at all.
If you want to have MATLAB alter the text, then there is no need to get notepad involved. Simply read in the file, make your alterations and write it back out again. These will be useful: fopen(), fgetl(), fprintf(), fclose().
Catégories
En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!