DEPRECATED: Imports a CSV file (comma-separated-value) in a matrix variable interactively.
[csvMat] = DI_readcsv() [csvMat] = DI_readcsv(path) [csvMat, exitID] = DI_readcsv() [csvMat, exitID] = DI_readcsv(path)
a string, target path for the file selector (OPTIONAL)
a string, name of the matrix which stores the imported data
an integer, exit codes, 0=OK, -1, -2, -3, -4=error codes, see below.
Read numerical data from a comma-separated-value (*.csv) or another text-based data file (*.dat, *.txt) and stores it into a matrix variable interactively.
The following field delimiters are accepted: Comma, semicolon, space(s), tabular(s). The decimal delimiter can be point or comma.
![]() | Note that the file has to be correctly formated. All rows have to have the
same number of columns. |
![]() | This function is DEPRECATED. Use DI_read instead! To avoid breaking legal scripts, the code will stay in the toolbox but will be removed from the documentation. |
You can commit an optional path to the function. This is used to open the file selector at the committed target path. If you omit it your home directory is set as the target path.
This is the name of the matrix variable which will content the imported data for further processing in Scilab's console or in a script.
The exitID gives a feedback what happened inside the function. If something went wrong csvMat is always [] (empty). To handle errors in a script you can evaluate exitID's error codes (negative numbers):
0: Everything is OK. Matrix csvMat was created
-1: User canceled file selection
-2: User canceled parameter dialog box
-3: Cannot read or interpret CSV file
-4: Cannot interpret file correctly - maybe header present
Import Parameter:
This is the character which separates the fields and numbers, resp. In general CSV-files it is the comma (,), in European ones it is often the semicolon (;). Sometimes it is a tabulator (tab). Text-based data files has a space or spaces as delimiters. E.g. to specify a tabulator as separator, type in the word "tab", for a space separator the word "space" without quotes.
The character which indentifies the decimal place. In general CSV files it is the point (.), in most European ones it is the comma (,).
The number of lines to be ignored at the beginning of the file. This is useful to skip table headers.
The row/column at which the import is going to start. Type a number. 1 means import starts at row/column 1 inclusively.
The row at which the import is going to end. Type a number or $ (dollar- sign). 12 means the import stops at row 12 inclusively, $ means that all rows/columns are read to the end.
All rows have to have the same number of columns. That does not mean that every cell has to be occupied by a number. Only the separator has to be present:
2.3 , 4.4 , 7.6 , 9.5 5.6 , 6.9 , ,
Strings or missing data (see above) are represented as Nan (not-a-number) in the matrix. E.g.:
2.3 4.4 7.6 9.5 5.6 6.9 Nan Nan
All rows have to have the same number of columns and should not contain strings (text). Otherwise the data will be imported as a string matrix and not a number matrix.
| 2.3 4.4 7.6 9.5 | | | | 5.6 6.9 |
[mat, id] = DI_readcsv(fullfile(DI_getpath(), "demos")); // Read CSV file disp("Exit-ID: "+string(id),mat,"data:") // Displays imported data "mat" and exit code "id" if id == 0 then // Plot data if import was successful plot(mat(:,1),mat(:,14),"-") xtitle("Central England Temperature","Year","Mean Temperature [°C]") end | ![]() | ![]() |