How to delete partial sub-string

1 view (last 30 days)
Mekala balaji
Mekala balaji on 18 Apr 2018
Commented: Mekala balaji on 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'

Accepted Answer

Jan
Jan on 18 Apr 2018
Edited: Jan on 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 Comment
Mekala balaji
Mekala balaji on 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'}

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!