How to delete partial sub-string

1 visualización (últimos 30 días)
Mekala balaji
Mekala balaji el 18 de Abr. de 2018
Comentada: Mekala balaji el 18 de Abr. de 2018
Hi,
I have below cell array,
input:
{'JAK2';'JAKKVAR2KL';'JAKAKR8DW';'JAKK4';'JAK19';'JAKNUI87YU';'JAK0'}
I want to remove JAK,
My desired output:
{'2';'KVAR2KL';'AKR8DW';'K4';'19';NUI87YU';'0'}
I used strtok but I am not getting desired output,
data={'JAK2';'JAKKVAR2KL';'JAKAKR8DW';'JAKK4';'JAK19';'JAKNUI87YU';'JAK0'}
data =
7×1 cell array
'JAK2'
'JAKKVAR2KL'
'JAKAKR8DW'
'JAKK4'
'JAK19'
'JAKNUI87YU'
'JAK0'
>> a=strtok(data,'JAK')
a =
7×1 cell array
'2'
'V'
'R8DW'
'4'
'19'
'NUI87YU'
'0'

Respuesta aceptada

Jan
Jan el 18 de Abr. de 2018
Editada: Jan el 18 de Abr. de 2018
C = {'JAK2';'JAKKVAR2KL';'JAKAKR8DW';'JAKK4';'JAK19';'JAKNUI87YU';'JAK0'};
D = strrep(C, 'JAK', '')

strtok splits the string, when the key occurs. But you want to delete the key. Then strrep with an empty string works.

  1 comentario
Mekala balaji
Mekala balaji el 18 de Abr. de 2018
Sir,
if my original input is:
{'2';'KVAR2KL';'AKR8DW';'K4';'19';NUI87YU';'0'}
and I want to combine each cell (row) with JAK (JAK should attach to left side of each cell row), how to get desired output as below:
{'JAK2';'JAKKVAR2KL';'JAKAKR8DW';'JAKK4';'JAK19';'JAKNUI87YU';'JAK0'}

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by