Search code examples
arraysmatlabcellcell-array

Deleting values from an element of a cell array


Column 2 of cell array X provides me with the following codes:

'00000127'

'00010121'

'00040486'

'00003702'

'00010077'

'00000002'

'00000050'

etc …

And I only want to have the last numbers (the numbers on the right), for instance like this:

'127'

'10121'

'40486'

'3702'

'10077'

'2'

'50'

I am finding difficulties, because I want to erase the zero values I have on the left side of the element. So, unless they are in between two numbers or on the right of other number, zero values should go out.

How can I do it?


Solution

  • One sort of messy approach -

    X(:,2) = strtrim(cellstr(num2str(cellfun(@str2num,X(:,2)))))