Convert cell, containing decimal points as a comma, to double

9 views (last 30 days)
Hi all,
I have a cell vector with numbers where the decimal point is a comma. How do I convert these to numbers?
Let's use an example:
A = '-68,8';
I want to convert this to the number -68.8.
str2double(A) gives:
-688
str2num(A) gives:
-68 8
Can you please help me?
Best regards,
Fredrik (using R2021a)

Accepted Answer

Fredrik
Fredrik on 27 Sep 2023
Moved: Dyuman Joshi on 27 Sep 2023
As always, I found the answer right after posting. If I use
A = str2double(strrep(A,',','.'))
it seems to work.
  1 Comment
Dyuman Joshi
Dyuman Joshi on 27 Sep 2023
@Fredrik, since you found the solution before I posted my answer, I suggest you accept your own answer.
I will delete my answer after that.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!