Read txt file with comma decimal separator in MATLAB

delkov

I have a txt file as such:

1,6 2 6,5 5 ...  // ~ 1000 columns 
0 1 4 2,5 ...
... // ~1000 rows

that is, "," as a decimal separator instead of "."

How to read this properly in MATLAB to output as such:

1.6 2 6 5 ...
0 1 4 2.5 ...
...
Suever

There is no easy built-in way of doing this (surprisingly!). You'll want to read in the entire file, then do a string replacement, and then convert the result into numbers.

% Read file in as a series of strings
fid = fopen('data.txt', 'rb');
strings = textscan(fid, '%s', 'Delimiter', '');
fclose(fid);

% Replace all commas with decimal points
decimal_strings = regexprep(strings{1}, ',', '.');

% Convert to doubles and join all rows together
data = cellfun(@str2num, decimal_strings, 'uni', 0);
data = cat(1, data{:});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to make InvariantCulture recognize a comma as a decimal separator?

From Dev

Why django uses a comma as decimal separator

From Dev

Jaxb conversion of number with comma as a decimal separator

From Dev

jQuery Validation Plugin: validate decimal number with comma as decimal separator

From Dev

seq uses comma as decimal separator

From Dev

NumericUpDown: accept both comma and dot as decimal separator

From Dev

R read comma delimited txt file with comma inside one column

From Dev

Convert a double to 2 decimal places with comma separator

From Dev

Masked EditText with comma as decimal separator

From Dev

C: Reading file from txt file and inserting into arrays. comma as a separator

From Dev

Read CSV with semicolon separated data with comma as decimal mark in matlab

From Dev

Show comma instead of point as decimal separator

From Dev

Format a decimal with comma as decimal separator and without thousands separator

From Dev

How do I read comma separated values from a .txt file in MATLAB using textscan()?

From Dev

Read txt file with comma decimal separator in MATLAB

From Dev

R: How can I read a CSV file with data.table::fread, that has a comma as decimal and point as thousand separator="."

From Dev

Parsing numbers with a comma decimal separator in JavaScript

From Dev

Only add thousand separator before decimal comma

From Dev

read a txt file to matrix and cellarray Matlab

From Dev

NumericUpDown: accept both comma and dot as decimal separator

From Dev

Convert a double to 2 decimal places with comma separator

From Dev

Pasting decimal numbers in excel / comma and point decimal separator

From Dev

Treat Comma and Period as Decimal Separator in Navision Decimal Fields

From Dev

Show comma instead of point as decimal separator

From Dev

Matlab: Read .txt file in matlab and save date

From Dev

bc: decimal separator comma vs. point

From Dev

STR_REPLACE from TXT file to string (with Comma Separator)

From Dev

Add comma separator to a numbers with 2 decimal points

From Dev

Google form regex for numbers with comma as decimal separator

Related Related

  1. 1

    How to make InvariantCulture recognize a comma as a decimal separator?

  2. 2

    Why django uses a comma as decimal separator

  3. 3

    Jaxb conversion of number with comma as a decimal separator

  4. 4

    jQuery Validation Plugin: validate decimal number with comma as decimal separator

  5. 5

    seq uses comma as decimal separator

  6. 6

    NumericUpDown: accept both comma and dot as decimal separator

  7. 7

    R read comma delimited txt file with comma inside one column

  8. 8

    Convert a double to 2 decimal places with comma separator

  9. 9

    Masked EditText with comma as decimal separator

  10. 10

    C: Reading file from txt file and inserting into arrays. comma as a separator

  11. 11

    Read CSV with semicolon separated data with comma as decimal mark in matlab

  12. 12

    Show comma instead of point as decimal separator

  13. 13

    Format a decimal with comma as decimal separator and without thousands separator

  14. 14

    How do I read comma separated values from a .txt file in MATLAB using textscan()?

  15. 15

    Read txt file with comma decimal separator in MATLAB

  16. 16

    R: How can I read a CSV file with data.table::fread, that has a comma as decimal and point as thousand separator="."

  17. 17

    Parsing numbers with a comma decimal separator in JavaScript

  18. 18

    Only add thousand separator before decimal comma

  19. 19

    read a txt file to matrix and cellarray Matlab

  20. 20

    NumericUpDown: accept both comma and dot as decimal separator

  21. 21

    Convert a double to 2 decimal places with comma separator

  22. 22

    Pasting decimal numbers in excel / comma and point decimal separator

  23. 23

    Treat Comma and Period as Decimal Separator in Navision Decimal Fields

  24. 24

    Show comma instead of point as decimal separator

  25. 25

    Matlab: Read .txt file in matlab and save date

  26. 26

    bc: decimal separator comma vs. point

  27. 27

    STR_REPLACE from TXT file to string (with Comma Separator)

  28. 28

    Add comma separator to a numbers with 2 decimal points

  29. 29

    Google form regex for numbers with comma as decimal separator

HotTag

Archive