フィルターのクリア

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 Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by