Convert comma-separated decimal to point-separated decimal

I have a table with 500 rows and 8 columns. The decimal separation is comma (,). However I would like to convert the separation to point(.)
Is it possible to do this without having to loop through the entire table?
Is there any function that permits conversion (something similar to strrep) when working with tables?

6 件のコメント

Walter Roberson
Walter Roberson 2017 年 6 月 29 日
What is the data type of the table at the moment? Is it in a text file of some kind (if so, what?) Is it a cell array of character vectors? Is a MATLAB table() object?
Darlington Mensah
Darlington Mensah 2017 年 6 月 29 日
It is a MATLAB table object with 8columns. Some columns are text files (usually the first 3 columns, although it is not always this way) and the rest are doubles with comma decimal separation.
Guillaume
Guillaume 2017 年 6 月 29 日
I was under the impression that matlab always used a dot (point) as a decimal separator for numeric types. Are you sure that "the rest are doubles with comma decimal separation" and not numbers stored as text?
Darlington Mensah
Darlington Mensah 2017 年 6 月 29 日
Im sorry i was not very clear. Once I import the data (with the readtable function), the decimal comma columns are stored as text. I would like to change convert the comma's to point and then get the element in these columns to be doubles
Egor Gurov
Egor Gurov 2021 年 9 月 11 日
Table.VarName = str2double(regexprep(Table.VarName,',','.'));
It works on Matlab 2020b
Matilda Jacobson
Matilda Jacobson 2022 年 4 月 19 日
Thank you Egor, it really helped me and my bachelor project!!

サインインしてコメントする。

回答 (2 件)

dpb
dpb 2017 年 6 月 29 日

1 投票

t.Var=str2double(strrep(t.Var,',','.');
for affected each variable 'Var' in table 't'.
Can generalize into loop or use whatever is most convenient addressing depending on structure of the table, just ensure the form used returns the variable content of the column not another table. See the
doc table % section on addressing for details
Walter Roberson
Walter Roberson 2017 年 6 月 29 日

0 投票

TheTable{:, ColumnNumber} = str2double( regexprep(TheTable{:,ColumnNumber}, ',', '.') );

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

質問済み:

2017 年 6 月 29 日

コメント済み:

2022 年 4 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by