MATLAB: Compact the values in a string

compactregular expressionsstring

Hi! I have a string '641 617 674 674 631 631 631 631 654 629 625 625 673 674': I want to delete duplicate. Ex
'641 617 674 674 631 631 631 631 654 629 625 625 673 674'
will became
'641 617 674 631 654 629 625 673 674'
can you help me?

Best Answer

Here's one way:
s = '641 617 674 674 631 631 631 631 654 629 625 625 673 674';
unique_s = num2str(unique(str2num(s),'stable'))