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

7 Ansichten (letzte 30 Tage)
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 Kommentar
Mathieu NOE
Mathieu NOE am 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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 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

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by