Convert a (rather complex) text file to mfile

조회 수: 22 (최근 30일)
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2022년 12월 5일
댓글: Voss 2022년 12월 6일
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

채택된 답변

Voss
Voss 2022년 12월 5일
"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
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2022년 12월 6일
Thanks a lot Voss!
Voss
Voss 2022년 12월 6일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by