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
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
2017년 6월 29일
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
2017년 6월 29일
Egor Gurov
2021년 9월 11일
Table.VarName = str2double(regexprep(Table.VarName,',','.'));
It works on Matlab 2020b
Matilda Jacobson
2022년 4월 19일
Thank you Egor, it really helped me and my bachelor project!!
답변 (2개)
dpb
2017년 6월 29일
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
2017년 6월 29일
TheTable{:, ColumnNumber} = str2double( regexprep(TheTable{:,ColumnNumber}, ',', '.') );
카테고리
도움말 센터 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!