MATLAB: Regex replace whole word MATLABstrings Hi, How to change 'v1 = v1a;' to 'v(1) = v1a;' using regex or regexrep? regexprep('v1 = v1a','\bv1\b','v(1)') apparently does not work. Best Answer >> regexprep('v1 = v1a','^([a-z]+)(\d+)','$1($2)')ans = v(1) = v1aHopefully you are not constructing arbitrary strings of code for evaluating! Related SolutionsMATLAB: How to define an arbitrary constant for equations If you are talking about making an assumption, you can do it as follows:v1=6;v3=18;syms v2 v4 v5 v6eqn1= -v4+v5==-v3;eqn2= -v2+v6==v3;eqn3= -v5-v6==-v1;assume(v6~=0)[v2 v4 v5 v6]=solve(eqn1, eqn2, eqn3);[v2 v4 v5 v6] MATLAB: How to replace string that perfectly matchs the string str = 'a = 1; b = 2; var1 = a + b; bar1 = a*b;';new_str = regexprep(str, 'a\>', 'v1');Result:new_str = 'v1 = 1; b = 2; var1 = v1 + b; bar1 = v1*b;'See Anchors: https://www.mathworks.com/help/matlab/ref/regexprep.html#btrbo5i_sep_shared-expression in the documentation. Related QuestionHow to extract strings with varied length by regular expressionHow do i create new variable from 31 variables with one columnHow to define norm of a vector as a symbolic functionDisable solve function warningsHow to concatenate string vectors of unequal length
Best Answer