How to remove first charachter from a string inside a cell

8 visualizaciones (últimos 30 días)
Ramiro Rea
Ramiro Rea el 25 de Jul. de 2017
Comentada: Ramiro Rea el 25 de Jul. de 2017
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

Respuesta aceptada

per isakson
per isakson el 25 de Jul. de 2017
Editada: per isakson el 25 de Jul. de 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 comentario
Ramiro Rea
Ramiro Rea el 25 de Jul. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by