turn a table column into doubles

98 visualizaciones (últimos 30 días)
JFz
JFz el 25 de Oct. de 2016
Editada: Arshey Dhangekar el 8 de Jul. de 2021
Hi,
I have a Table that has a column that was read from an excel sheet. The column should be numbers but is currently shown as strings like '3.14', '2.22', .... How to turn this column into doubles?
Thanks.
jennifer

Respuesta aceptada

Guillaume
Guillaume el 25 de Oct. de 2016
yourtable.columnname = str2double(yourtable.columnname);
is all that is needed.
  5 comentarios
Luisana Rodriguez Sequeira
Luisana Rodriguez Sequeira el 24 de Nov. de 2020
What can we do if str2double returns NaN?
Image Analyst
Image Analyst el 24 de Nov. de 2020
The the column is either nans or characters or something that is not a number. So don't try to cast it to doubles then!

Iniciar sesión para comentar.

Más respuestas (3)

Chaya N
Chaya N el 25 de Oct. de 2016
str2num('enter your string here');
Please note that this would only work for strings that contain numerical data
  7 comentarios
Chaya N
Chaya N el 26 de Oct. de 2016
I am learning new things here. Thank you.
JFz
JFz el 27 de Oct. de 2016
str2double works!
Thank you so much!

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 25 de Oct. de 2016
You could use xlsread() instead of readtable().

Priteshkumar Gohil
Priteshkumar Gohil el 12 de Mayo de 2021
Editada: Priteshkumar Gohil el 12 de Mayo de 2021
e.g. if you want to convert 1st column then following should work.
yourtable.(1) = str2double(t.(1));
or
yourtable.('COLUMN_TITLE') = str2double(t.('COLUMN_TITLE'));
  3 comentarios
Image Analyst
Image Analyst el 8 de Jul. de 2021
@Arshey Dhangekar, start your own question and attach the csv file and code to import it into MATLAB, presumably with the readtable() function.
Arshey Dhangekar
Arshey Dhangekar el 8 de Jul. de 2021
Editada: Arshey Dhangekar el 8 de Jul. de 2021
Hello I know basic thing. So only I want to know how can I convert all data into double. I attach csv file
Press=readtable ("inst0 138.221.155.184 12_10_2020 14_49_56 2.csv")
varfun(@class,Press,'OutputFormat','cell')
Output
Columns 1 through 8
{'double'} {'cell'} {'double'} {'double'} {'double'} {'double'} {'double'} {'double'}
Columns 9 through 16
{'double'} {'double'} {'double'} {'double'} {'double'} {'double'} {'double'} {'double'}
Columns 17 through 25
{'double'} {'double'} {'cell'} {'cell'} {'cell'} {'cell'} {'cell'} {'cell'} {'cell'}
Columns 26 through 29
{'cell'} {'cell'} {'cell'} {'double'}

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by