How to delete partial sub-string

1 visualizzazione (ultimi 30 giorni)
Mekala balaji
Mekala balaji il 18 Apr 2018
Commentato: Mekala balaji il 18 Apr 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'

Risposta accettata

Jan
Jan il 18 Apr 2018
Modificato: Jan il 18 Apr 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 Commento
Mekala balaji
Mekala balaji il 18 Apr 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'}

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by