MATLAB: How to update variable names after a “clear”

clearclearvarsrenameupdated

Dear Community,
I wonder if there is another way to clear variables. If I do:
clear var1 var2
% or
clearvars('var1','var2')
The variables are strings or purple and are not updated if the name of the variable is changed.
How can I realize that variables after a clear or clearvars are updated if the variable name is changed. (e.g. the original variable name was not descriptive enough).
Edit: I mean not during running the code, the variable name is not dynamic! I mean during writing, the editor offers you the possibility to rename all instances of a variable (Shift-Enter)
>> Press Shift+Enter to rename 4 instances of " var1" to " anothernameOfVar1"
within a script. Variables after a clear or clearvars are not affected by this.
Best, Robin

Best Answer

Unfortunately, this is a limitation of matlab's editor.
Note that
clear x
is exactly the same as
clear('x')
The former is the command form of the latter. In both cases, the input to clear is the char array 'x'.
The automatic renaming does not look in char arrays, strings or comments. So as Rik commented, the only way to deal with that is by doing the renaming yourself.
Matlab refactoring tools have thankfully improved over the years but are still way behind what is available in other editors (It really pales when compared to Visual Studio).