# How to convert cell aray which contains numeric to double

1 visualizzazione (ultimi 30 giorni)
Arif il 9 Feb 2024
Commentato: Arif il 9 Feb 2024
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
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Vaibhav il 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:
1. Extract the string from the cell.
2. Replace the comma with a period.
3. Convert the string to a double.
Here's an example code:
% Cell array with a string containing a comma as decimal separator
cellArray = {'0,037796'}
cellArray = 1×1 cell array
{'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)
doubleValue = 0.0378
% 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, '.', '')
stringValueNoDecimal = '0037796'
% Now convert the modified string to a double
doubleValueNoDecimal = str2double(stringValueNoDecimal)
doubleValueNoDecimal = 37796
% Display the result
disp(doubleValue);
0.0378
Hope this helps!
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Arif il 9 Feb 2024
thank you so much....

Accedi per commentare.

### Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

R2023b

### Community Treasure Hunt

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

Start Hunting!

Translated by