how to find and replace a number/word/command in all opened *.m files in matlab at once?

7 visualizaciones (últimos 30 días)
How to find and replace a particular number/word/command in the multiple opened *.m files at once?
I want to change one particular X-Label from 50 different files. It is difficult to do it 50 times and run. So, I can find and replace it in all the opened matlab documents in a single click? Any help in this context will be highly appriciated.
Thank you in advance.
  1 comentario
Mathieu NOE
Mathieu NOE el 9 de Feb. de 2021
hello
FYI, you can do it outside matlab in a regular text editor
I use Textpad (freeware) which is quite powerfull, open all kind of ascii / txt files (including m files)
use the menu "replace" in all opened files and do the update , then save all
of course you can also do a matlab function for that

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 9 de Feb. de 2021
If the files are located in the same folder, grepWin can do this for you in Windows: https://tools.stefankueng.com/grepWin.html
You can do this by a function also:
function ReplaceInEditor(From, To)
AllDoc = matlab.desktop.editor.getAll;
for iDoc = 1:numel(AllDoc)
Doc = AllDoc(iDoc);
Text = strrep(Doc.Text, From, To);
if ~isequal(Text, Doc.Text)
Doc.Text = Text;
fprintf('Updated: %s\n', Doc.Filename);
end
end

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by