replace function that fulfills criteria

1 回表示 (過去 30 日間)
Cside
Cside 2021 年 5 月 20 日
回答済み: Sulaymon Eshkabilov 2021 年 5 月 20 日
Hi, I am currently using the replace function for my strings. For example, if the string contains 1, i will have it replaced with another string of numbers.
However, I realized that there are overlaps in the strings, for eg, replace (A, '1', '1234'), replace(A, '2', '12345'). So this means that my '2' will be replaced in the previous string as well, with the output '11234534'.
What can I write so that I specifically identify strings and replace those strings that contain only 1 digit? My desired output is that all the strings in this array to be replaced correspondingly ie all '1' to be '1234', '2' to be '12345'.
Thank you!

回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 5 月 20 日
Is that what you are tryin to obtain:
A = '12'
A1=replace (A, '1', '1234')
A2=replace (A1, '2', '12345')
...

カテゴリ

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