Clear Filters
Clear Filters

Change digits in strings

1 view (last 30 days)
Mariusz
Mariusz on 10 May 2016
Commented: arthur doroshev on 15 Dec 2020
Hello,
I have a problem. How I can change digits in string for example:
"A[12,12]*A[12,12]+A[9,12]*A[12,9]+A[5,2]*A[1,3]"
to have
"A[11,11]*A[11,11]+A[8,11]*A[11,8]+A[4,1]*A[0,]"
using regexprep ?
Best

Accepted Answer

Guillaume
Guillaume on 10 May 2016
You need to use a dynamic replacement string
str = '"A[12,12]*A[12,12]+A[9,12]*A[12,9]+A[5,2]*A[1,3]"';
regexprep(str, '\d+', '${num2str(str2double($0)-1)}')
  8 Comments
Mariusz
Mariusz on 23 May 2016
Hello,
Thank you for help.
Best
Mariusz
arthur doroshev
arthur doroshev on 15 Dec 2020
and if you want to get from
'A[12,12]*A[12,12]+A[9,12]*A[12,9]+A[5,2]*A[1,3]'
that
'A[1]*A[2]+A[3]*A[4]+A[5]*A[6]'
what to do then?

Sign in to comment.

More Answers (0)

Categories

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!