I need to convert comma ',' to dot '.'

조회 수: 55 (최근 30일)
matt sss
matt sss 2021년 6월 10일
댓글: Sulaymon Eshkabilov 2021년 6월 10일
Hi, I have a set of txt files that contain only a set of numbers that have decimals, but have a comma and not a dot as a separator (for example, there is 1567,987 and not 1567.987). Is there a script that allows you to do this conversion?
I could use matlab's "find & replace" option and import the files later, however, since there are so many files I would like to do something more automated with a script.
  댓글 수: 1
Stephen23
Stephen23 2021년 6월 10일
If your actual goal is to import the data then READTABLE et al will correctly parse files with decimal commas:

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

답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 6월 10일
편집: Jan 2021년 6월 10일
  댓글 수: 2
Jan
Jan 2021년 6월 10일
I can confirm, that this is a good advice. :-)
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 6월 10일
Thanks Jan :)

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


Star Strider
Star Strider 2021년 6월 10일
One option in detectImportOptions (introduced in R2016b and updated in later releases) in Parameters for Text Files Only allows the definition of:
'ThousandsSeparator' — Characters that indicate the thousands grouping
and:
'DecimalSeparator' — Characters indicating decimal separator
There is no direct URL for these, so click on the second link and scroll down to them.
.

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by