Change variable name across code lines

20 ビュー (過去 30 日間)
Ahmed
Ahmed 2023 年 11 月 28 日
編集済み: DGM 2023 年 11 月 28 日
I have a long that consists of over 600 lines, I have a variable “a” that I use a lot in my code and I would like to change its name to variable app.a to use in app designer however using the replace all feature changes all occurances of “a” even the ones in my comments or in other words in my code

採用された回答

DGM
DGM 2023 年 11 月 28 日
編集済み: DGM 2023 年 11 月 28 日
This behavior might have changed in the newer versions, but I think I have a way that might work.
If you look for a place where you made an assignment to a, such as:
a = 2;
You can select the variable name and start typing a new name. You should see a tooltip pop up that says you can rename all uses of this variable by hitting Shift+Enter.
The problem with this is that AFAIK, you can't enter a dot indexing expression this way. The workaround would be to use a unique temporary variable name. Say you use this renaming feature to rename all uses of 'a' to:
someuniquename1234 = 2;
Now you can do a simple search and replace on all instances of the temporary unique name.

その他の回答 (1 件)

John D'Errico
John D'Errico 2023 年 11 月 28 日
Use find and replace.
It will search for the next occurence of a. Then you click on either replace, or to ignore that occurence of a, and go on to the next occurrence.
You won't find something simpler, and you will find that by the time you are done, it did not take too long.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by