Imports a CSV file (comma-separated-value) in a matrix variable interactively
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 data from a comma-separated-value (*.csv) or another text-based data file (*.dat, *.txt) and stores it into a matrix variable interactively.
![]() | Note that the file has to be correctly formated. All rows have to have the
same number of columns. |
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 rows you want to select for import. E.g. "2:5" imports rows 2, 3, 4 and 5. "2:$" starts the import at row 2 and imports all following rows till the last row is reached. ":" means all rows.
The columns you want to select for import. Refer the description of "row range" above for details.
With row and column range you can import a subset of your raw data table for further processing.
For CSV and text-based data files there are different prerequisites to consider.
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 |