How to remove first charachter from a string inside a cell

7 views (last 30 days)
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

Accepted Answer

per isakson
per isakson on 25 Jul 2017
Edited: per isakson on 25 Jul 2017
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.
  1 Comment
Ramiro Rea
Ramiro Rea on 25 Jul 2017
Thanks, this solves the issue. By any chance do you know how to transform this columns to numbers? cell2mat doesn't work. If I transpose the column to use cell2mat,it does this:
d = data_SVO(:,3);
c = cell2mat(d.');
c =
8.58.57.58.5106.3
I know is not related to the original question, but maybe you have a solution for this. Thanks again.

Sign in to comment.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!