Last active
June 24, 2022 13:59
-
-
Save kitswas/34befa9d22c08a2ee79e2614eac92e3c to your computer and use it in GitHub Desktop.
Reads numbers with comma as a decimal separator from CSV files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % -- DATA = read_improper_csv(FILE, NROWS, NCOLUMNS, DELIM, SKIP_LINES) | |
| function data=read_improper_csv(file, nrows, ncolumns, delim=";", header_lines=0) | |
| if (nargin() < 3 || nargin() > 5) | |
| print_usage (); | |
| endif | |
| data = textscan (fopen(file, 'r'), "%s", "Delimiter", delim, "HeaderLines", header_lines); | |
| data = cell2mat(data); | |
| data = str2double(strrep(data,',','.')); | |
| data = reshape(data, ncolumns, nrows); % elements are accessed in column-major order | |
| data = transpose(data); | |
| endfunction |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See the following question on StackOverflow for the motivation behind this script.
How to read CSV files with GNU Octave if the delimiter is ;?