필터 지우기
필터 지우기

Change digits in strings

조회 수: 1 (최근 30일)
Mariusz
Mariusz 2016년 5월 10일
댓글: arthur doroshev 2020년 12월 15일
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

채택된 답변

Guillaume
Guillaume 2016년 5월 10일
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
Mariusz
Mariusz 2016년 5월 23일
Hello,
Thank you for help.
Best
Mariusz
arthur doroshev
arthur doroshev 2020년 12월 15일
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?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by