Arun Kumar
Arun Kumar

Reputation: 103

how to remove duplicate words in a string in matlab

consider I have this string

a='flexray_datain_flexray_sensors'

and I want to process this string to get

a='flexray_datain_sensors'

And the thing is this can be for any repeated words and not just flexray in matlab. If I already know what the word is then it's easy

I tried:

 parts = textscan(bypname , '%s', 'delimiter', '_');
    parts = parts{:};

and then processing this cell(parts) using unique or something and removing the repeated words. But I need a better answer .

Upvotes: 1

Views: 487

Answers (1)

Dan
Dan

Reputation: 45741

Does this work for you?

strjoin(unique(strsplit(a,'_'),'stable'),'_')

Upvotes: 3

Related Questions