Azzera filtri
Azzera filtri

Change digits in strings

1 visualizzazione (ultimi 30 giorni)
Mariusz
Mariusz il 10 Mag 2016
Commentato: arthur doroshev il 15 Dic 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

Risposta accettata

Guillaume
Guillaume il 10 Mag 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 Commenti
Mariusz
Mariusz il 23 Mag 2016
Hello,
Thank you for help.
Best
Mariusz
arthur doroshev
arthur doroshev il 15 Dic 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?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by