How to find and replace within *.mlx (Live Scripts), across multiple files?

조회 수: 17 (최근 30일)
Bradley Stiritz
Bradley Stiritz 2018년 4월 20일
댓글: adams13 2019년 9월 4일
As of R2018a, Matlab does not offer any way to search and replace text, across multiple files. This is a must-have for refactoring larger code bases. (Third-party) UltraEdit's feature "Find/replace in files" is extremely versatile with *.m files, but does not work at all on Matlab's binary format *.mlx (Live Script).
Has anyone found an effective tool? Or will this likely be an ongoing limitation of *.mlx ?
Update 5/10/2018 : one workaround is to conscientiously create M files for all MLX files, which can then be searched normally. In Live Editor, "Save As" M file. Note that as of R2018a, Live Editor does not offer "Save Copy As".

답변 (1개)

adams13
adams13 2018년 6월 1일
There are convert functions (see here ): from mlx to m
matlab.internal.liveeditor.openAndConvert
from m to mlx
matlab.internal.liveeditor.openAndSave
Works like
%%Save as a .m file for easy source control
mlx_file = 'MyFile.mlx';
m_file = 'MyFileCopy.m';
disp(['Save ' m_file])
% https://de.mathworks.com/matlabcentral/answers/271478-how-do-i-go-between-plain-scripts-m-and-live-scripts-mlx
matlab.internal.liveeditor.openAndConvert(mlx_file, m_file);
You can convert all .mlx files to .m using a script, perform an edit and convert back with another script.
  댓글 수: 2
Bradley Stiritz
Bradley Stiritz 2018년 7월 9일
편집: Bradley Stiritz 2018년 7월 10일
Hi adams13, thanks for your answer and for mentioning the internal conversion functions.
If I understand you correctly, you are suggesting that I essentially write my own general-purpose "Find and Replace" utility for MLX files?
This is an interesting idea. I'm guessing it would require a decent investment of time to produce something absolutely bulletproof, and with a good feature set. I am over-committed already with current projects, and would not be able to take this on myself.
My personal view is that Mathworks should provide this functionality, via "Find in Files" enhancement, in order to better support the new MLX file type.
adams13
adams13 2019년 9월 4일
The "grown up" development environments like Visual Studio (and many others) use essentially text files for the source code and probably some binary files for the internal stuff that can be easily recreated. This way you can always see in the source control what exactly was changed in every file. You can also see in which changeset (or revision) and from wich developer every line of the source code appeared. This makes way easier and faster to understand the meaning and the reason and the side effects. Unfortunetly MathWorks is not yet at that level, you get just a colorfull toy to play with. Their technical support even do not know that there is Subversion client built in into Matlab.
I think refactoring (like variable/function rename over files, extract function, etc.) is also quite a far future for Matlab.

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

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by