Borrar filtros
Borrar filtros

Change digits in strings

1 visualización (últimos 30 días)
Mariusz
Mariusz el 10 de Mayo de 2016
Comentada: arthur doroshev el 15 de Dic. de 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

Respuesta aceptada

Guillaume
Guillaume el 10 de Mayo de 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 comentarios
Mariusz
Mariusz el 23 de Mayo de 2016
Hello,
Thank you for help.
Best
Mariusz
arthur doroshev
arthur doroshev el 15 de Dic. de 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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by