turn a table column into doubles
61 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
Guillaume
2016 年 10 月 25 日
yourtable.columnname = str2double(yourtable.columnname);
is all that is needed.
5 件のコメント
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
2016 年 10 月 25 日
str2num('enter your string here');
Please note that this would only work for strings that contain numerical data
7 件のコメント
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
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
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 Center および File Exchange で Data Type Conversion についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!