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

조회 수: 10 (최근 30일)
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
Mathieu NOE
Mathieu NOE 2021년 2월 9일
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

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

채택된 답변

Jan
Jan 2021년 2월 9일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by