turn a table column into doubles

조회 수: 41 (최근 30일)
JFz
JFz 2016년 10월 25일
편집: Arshey Dhangekar 2021년 7월 8일
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

채택된 답변

Guillaume
Guillaume 2016년 10월 25일
yourtable.columnname = str2double(yourtable.columnname);
is all that is needed.
  댓글 수: 5
Luisana Rodriguez Sequeira
Luisana Rodriguez Sequeira 2020년 11월 24일
What can we do if str2double returns NaN?
Image Analyst
Image Analyst 2020년 11월 24일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Chaya N
Chaya N 2016년 10월 25일
str2num('enter your string here');
Please note that this would only work for strings that contain numerical data
  댓글 수: 7
Chaya N
Chaya N 2016년 10월 26일
I am learning new things here. Thank you.
JFz
JFz 2016년 10월 27일
str2double works!
Thank you so much!

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2016년 10월 25일
You could use xlsread() instead of readtable().
  댓글 수: 1
JFz
JFz 2016년 10월 25일
Will try it. Thanks.

댓글을 달려면 로그인하십시오.


Priteshkumar Gohil
Priteshkumar Gohil 2021년 5월 12일
편집: Priteshkumar Gohil 2021년 5월 12일
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
Image Analyst
Image Analyst 2021년 7월 8일
@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 2021년 7월 8일
편집: Arshey Dhangekar 2021년 7월 8일
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'}

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by