Search code examples
stringmatlabreplacecellvectorization

Cell array vectorization in Matlab


I have a cell array that contains string.

Those individual string needs to be processed, like for example:

 a  = {'1,2','12';'2,3','23'}

in which, comma should be removed from the string.

I don't know if what's the speed of using for loop compared with using vectorization.

But how can I achieve that using vectorization?


Solution

  • You can use strrep to replace characters in a string, like this:

    EDU>> a = {'1,2','12';'2,3','23'}
    a = 
        '1,2'    '12'
        '2,3'    '23'
    EDU>> strrep(a,',','')
    ans = 
        '12'    '12'
        '23'    '23'