Convert a (rather complex) text file to mfile

24 visualizaciones (últimos 30 días)
Mohammad Shojaei Arani
Mohammad Shojaei Arani el 5 de Dic. de 2022
Comentada: Voss el 6 de Dic. de 2022
Hello,
I have a text file which is just a scan of an mfile. I need to convert this into an mfile (spent ours on it but
unfortunately could not figour out how to do this). Please note that if I would only have one text file I could do this manually. So,
my question is about a bunch of files not a single file. So, I like to do this by coding. For this file I cannot use commands like str2func, unfortunately.
To make everything clear I am attaching a text file called temp.txt.
Thanks for your kind help in advance,
Babak

Respuesta aceptada

Voss
Voss el 5 de Dic. de 2022
"I have a text file ... I need to convert this into an mfile"
m-files are text files, so you just need to change the extension from .txt to .m, right?
files = dir('*.txt'); % an appropriate call to dir() to get info about your files,
% e.g., if they are all in C:\Docs\, use files = dir('C:\Docs\*.txt')
for ii = 1:numel(files)
fullFileName = fullfile(files(ii).folder,files(ii).name);
[filePath,fileName,~] = fileparts(fullFileName);
movefile(fullFileName,fullfile(filePath,[fileName '.m']));
end
  2 comentarios
Mohammad Shojaei Arani
Mohammad Shojaei Arani el 6 de Dic. de 2022
Thanks a lot Voss!
Voss
Voss el 6 de Dic. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by