How to remove first charachter from a string inside a cell

9 ビュー (過去 30 日間)
Ramiro Rea
Ramiro Rea 2017 年 7 月 25 日
コメント済み: Ramiro Rea 2017 年 7 月 25 日
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

採用された回答

per isakson
per isakson 2017 年 7 月 25 日
編集済み: per isakson 2017 年 7 月 25 日
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 件のコメント
Ramiro Rea
Ramiro Rea 2017 年 7 月 25 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by