how to find and replace a number/word/command in all opened *.m files in matlab at once?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Mathieu NOE
le 9 Fév 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
Réponse acceptée
Jan
le 9 Fév 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
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Environment and Settings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!