フィルターのクリア

how to convert text values between char arrays

3 ビュー (過去 30 日間)
giovanni negro
giovanni negro 2018 年 1 月 29 日
回答済み: Harish Ramachandran 2018 年 2 月 2 日
Hi everybody,
I have a char/cell array like this A=['a';'bb';'ccc';'a';'ccc';'ccc';'bb'] and I want a new char/cell array like this B['xxx';'yy';'z';'xxx';'z';'z';'yy'], where 'a'='xxx', 'bb'='yy' and 'ccc'='z', How can I get this score? This is just an exemple, imagine that my A array is a char array 86x5 or bigger.
Thanks a lot.
  1 件のコメント
giovanni negro
giovanni negro 2018 年 1 月 29 日
I tried with strrep and it worked but I had to replace every single value like this: A1=strrep(A,'a','xxx') A2=strrep(A1,'bb','yy') A3=strrep(A2,'ccc','z')
For sure there is a smarter way...

サインインしてコメントする。

回答 (1 件)

Harish Ramachandran
Harish Ramachandran 2018 年 2 月 2 日
Create two vectors containing the correlation between the original word and the substitution word.
Then use a element-wise function like arrayfun or cellfun (in the case of cell array) in order to apply the strrep function to each element of the array by passing it as a function handle.

カテゴリ

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