How to delete partial sub-string

1 Ansicht (letzte 30 Tage)
Mekala balaji
Mekala balaji am 18 Apr. 2018
Kommentiert: Mekala balaji am 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'

Akzeptierte Antwort

Jan
Jan am 18 Apr. 2018
Bearbeitet: Jan am 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 Kommentar
Mekala balaji
Mekala balaji am 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'}

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by