Programmatically "Find" and "Select"

2 vues (au cours des 30 derniers jours)
Gabriel
Gabriel le 13 Août 2015
Réponse apportée : Jan le 14 Août 2015
Hello all,
I wish to programmatically find and select a portion of text in the Editor Window, given the portion of text. Something like the "Find and Replace" command does, but I would like to have this programmatically and not using the Ctrl+F window. Is this possible using MATLAB?
Thanks for all help!
Gabriel

Réponses (2)

Steven Lord
Steven Lord le 13 Août 2015
Use the Editor API to get a handle to the document in the Editor. See "help matlab.desktop.editor" for more information about this API. Use the string processing functions in MATLAB to modify the contents of the Text property of the document object to modify the document.
>> edit bench.dat
>> document = matlab.desktop.editor.getActive;
>> T = document.Text;
>> T(1:6)
ans =
MATLAB
>> T(1:6) = 'Steven';
>> document.Text = T;

Jan
Jan le 14 Août 2015

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by