I have a cell array like this :
Input = {'CEEEGH';'CCEEG';'ABCDEFF';'BCFGG';'BCDEEG';'BEFFH';'AACEGH'}
How can I delete all of the repeated characters and just keep only 1 character left in each string in the Input ? The expected output should be like this:
Output = {'CEGH';'CEG';'ABCDEF';'BCFG';'BCDEG';'BEFH';'ACEGH'}
use :
cellfun(@unique,input,'UniformOutput',0)
ans =
'CEGH'
'CEG'
'ABCDEF'
'BCFG'
'BCDEG'
'BEFH'
'ACEGH'
EDIT:
To conserve ordering in case the letters are not sorted, as @thewaywewalk commented, you can use:
cellfun(@(x) unique(x,'stable'),input,'UniformOutput',0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With