フィルターのクリア

How to replace a character using strrep

1 回表示 (過去 30 日間)
Kanakaiah Jakkula
Kanakaiah Jakkula 2018 年 2 月 2 日
コメント済み: Jan 2018 年 2 月 4 日
Hi,
I have below cell array(contain string of characters and double), I want to replace "/" with "*" if exsit "/" in the name. My matlab version is R2012b. I give me error when the name is numeric: Error is: Cell elements must be char.
Input: {'PV05K/THF05/34' '40';'5' 'PV05K/THH12';'TjK05K' 'ZV45E/FGF47';'2' 'ZV45E/FGF47';'ZV95G/FGGF' 'ZA77G/KKGGF'}

採用された回答

Birdman
Birdman 2018 年 2 月 2 日
編集済み: Birdman 2018 年 2 月 2 日
regexprep or strrep will do it with only one line of code:
str={'PV05K/THF05/34' '40';'5' 'PV05K/THH12';'TjK05K' 'ZV45E/FGF47';'2' 'ZV45E/FGF47';'ZV95G/FGGF' 'ZA77G/KKGGF'}
strNew=regexprep(str,'/','*')
or
strNew=strrep(str,'/','*')
  3 件のコメント
Kanakaiah Jakkula
Kanakaiah Jakkula 2018 年 2 月 2 日
編集済み: Kanakaiah Jakkula 2018 年 2 月 2 日
Sir,
Initially, I used as below (in Matlab2012b): Input(:,1:2)=strrep(Input(:,1:2),'/','*'), But It give me error: "Cell elements must be char" I traced that the error occured where the cell elements are numeric.
Jan
Jan 2018 年 2 月 4 日
@Kanakaiah Jakkula: Exactly. strrep works on cell strings only. Your example data contains strings only. If this is not the case in the real data, please post a meaningful example.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Acquisition Toolbox Supported Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by