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

10 visualizzazioni (ultimi 30 giorni)
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 Commento
Mathieu NOE
Mathieu NOE il 9 Feb 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

Accedi per commentare.

Risposta accettata

Jan
Jan il 9 Feb 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

Più risposte (0)

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by