- Extract the string from the cell.
- Replace the comma with a period.
- Convert the string to a double.
How to convert cell aray which contains numeric to double
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
hi guys, can u help me how to convert cell to double but with in cell have comma as decimal separator ?
for example when i convert {'0,037796'}, it will be 37796. Thankyou
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1612336/image.jpeg)
0 Kommentare
Akzeptierte Antwort
Vaibhav
am 9 Feb. 2024
Hi Arif
I understand that you would like to convert cell aray which contains numeric to double. You can consider following the below steps:
Here's an example code:
% Cell array with a string containing a comma as decimal separator
cellArray = {'0,037796'}
% Extract the string from the cell
stringValue = cellArray{1};
% Replace the comma with a period
stringValue = strrep(stringValue, ',', '.');
% Convert the string to a double
doubleValue = str2double(stringValue)
% If you want to convert to a number without decimals (as your example suggests)
% you would remove the decimal point before converting
stringValueNoDecimal = strrep(stringValue, '.', '')
% Now convert the modified string to a double
doubleValueNoDecimal = str2double(stringValueNoDecimal)
% Display the result
disp(doubleValue);
Hope this helps!
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!