List variables in m-file

조회 수: 2(최근 30일)
Etienne Coetzee
Etienne Coetzee 2013년 4월 24일
I would like to rename some variables in an m-file, and would like to automate this process. I have tried using regexprep, but ran into some problems. I noticed a feature in the newest versions of Matlab, where you can automatically rename variables. Is there a command line version of this functionality. Alternatively, what would be the best way of renaming the variables, without having to run the file?
  댓글 수: 2
Etienne Coetzee
Etienne Coetzee 2013년 4월 25일
Yes, I have the names, but some variables are for instance N and NN, so I am not sure how to prevent NN from changing when I want to change N to AB for instance. NN will then become ABAB.

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

채택된 답변

Walter Roberson
Walter Roberson 2013년 4월 24일
Example of replacing a variable in a string:
S = 'x^2 + 3*x*y + x1/x';
regexprep(S, '(?<![A-Za-z0-9_])x(?![A-Za-z0-9_])', 'YO')
  댓글 수: 3
Walter Roberson
Walter Roberson 2013년 4월 25일
\w would likely be a good idea. I was thinking at the time that it matched a slightly different set of characters than was needed for MATLAB identifiers, but you are right that it is the same.

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

추가 답변(0개)


Find more on Characters and Strings in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by