MATLAB Answers

turn a table column into doubles

314 views (last 30 days)
JFz on 25 Oct 2016
Edited: Arshey Dhangekar on 8 Jul 2021
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?

Accepted Answer

Guillaume on 25 Oct 2016
yourtable.columnname = str2double(yourtable.columnname);
is all that is needed.
Image Analyst
Image Analyst on 24 Nov 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!

Sign in to comment.

More Answers (3)

Chaya N
Chaya N on 25 Oct 2016
str2num('enter your string here');
Please note that this would only work for strings that contain numerical data
JFz on 27 Oct 2016
str2double works!
Thank you so much!

Sign in to comment.

Image Analyst
Image Analyst on 25 Oct 2016
You could use xlsread() instead of readtable().
  1 Comment
JFz on 25 Oct 2016
Will try it. Thanks.

Sign in to comment.

Priteshkumar Gohil
Priteshkumar Gohil on 12 May 2021
Edited: Priteshkumar Gohil on 12 May 2021
e.g. if you want to convert 1st column then following should work.
yourtable.(1) = str2double(t.(1));
yourtable.('COLUMN_TITLE') = str2double(t.('COLUMN_TITLE'));
Arshey Dhangekar
Arshey Dhangekar on 8 Jul 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 12_10_2020 14_49_56 2.csv")
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'}

Sign in to comment.



Community Treasure Hunt

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

Start Hunting!

Translated by