MATLAB: How to remove first charachter from a string inside a cell

MATLABremove character from cellremove first character

Hi everyone,
I have a 6 x 5 cell array (see example file). I would like, for the 3th and 4th column to remove the first character (the symbol $), so I can do some operations with the data. I know how to do remove this in a single string, but when I am working with the column, it doesn't work. For instance if I put:
a = data_SVO{6,3};
c = c = a(2:end);
c =
6.3
Then c is the value without the '$'. I know probably is really simple, but I haven't managed to find a solution to this. I would appreciate if you could guide me to solve this issue.
Many thanks

Best Answer

One way with R2016a
>> load 20_SVO.MAT
>> data_SVO(:,3:4) = regexprep( data_SVO(:,3:4), '\$', '' );
>> data_SVO
data_SVO =
[6] [9] '8.5' '8.5' [ 5.9365]
[3] [9] '8.5' '8.5' [ 3.9902]
[5] [5] '7.5' '7.5' [14.4665]
[1] [1] '8.5' '8.5' [ 6.0439]
[2] [9] '10' '5' [20.5387]
[4] [4] '6.3' '6.8' [15.7036]
>>
or use a double loop.
Variants
  • Replace '\$' by '^\$' to be sure to only remove "$" when it's in the first position.
  • Replace '\$' by '^.' to remove the first character whatever it is.