Borrar filtros
Borrar filtros

How to replace a character using strrep

1 visualización (últimos 30 días)
Kanakaiah Jakkula
Kanakaiah Jakkula el 2 de Feb. de 2018
Comentada: Jan el 4 de Feb. de 2018
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'}

Respuesta aceptada

Birdman
Birdman el 2 de Feb. de 2018
Editada: Birdman el 2 de Feb. de 2018
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 comentarios
Kanakaiah Jakkula
Kanakaiah Jakkula el 2 de Feb. de 2018
Editada: Kanakaiah Jakkula el 2 de Feb. de 2018
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 el 4 de Feb. de 2018
@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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Acquisition Toolbox Supported Hardware en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by