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

8 Ansichten (letzte 30 Tage)
Fredrik
Fredrik am 27 Sep. 2023
Kommentiert: Dyuman Joshi am 27 Sep. 2023
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)

Akzeptierte Antwort

Fredrik
Fredrik am 27 Sep. 2023
Verschoben: Dyuman Joshi am 27 Sep. 2023
As always, I found the answer right after posting. If I use
A = str2double(strrep(A,',','.'))
it seems to work.
  1 Kommentar
Dyuman Joshi
Dyuman Joshi am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by