readdata
read numerical data from text files
Calling Sequence
Parameters
Description
Examples
readdata(fileID, n)
readdata(fileID, format, n)
readdata(fileID, format)
fileID
-
symbol or string; file name or file descriptor of the data file
n
positive integer; specifies the number of columns of data
format
integer, float, or string or a list containing these names; specifies the format of the data that is read
The readdata function reads numeric data from a text file into Maple. The data in the file must consist of integers or floating-point values arranged in columns, separated by white space.
If only one column of data is read, the output is a list of the data. If more than one column is read, the output is a list of data corresponding to the rows of data in the file for the specified columns.
To read numerical data and store it in a Matrix or Vector, see ImportMatrix and ImportVector.
The first form of the calling sequence for the readdata function reads n columns of numerical data in floating-point format from the file specified by fileID.
The second and third calling sequence for readdata specify whether the data is read as integer, floating-point, or string data. The format parameter must be one of integer, float, or string, or a list containing one or more of these.
Note: The procedure readline is used to read a line of data from the file and the data is extracted by using sscanf.
While integers can be read as floating-point numbers, floating-point numbers should not be read in as integers.
If a file name is specified (instead of a file descriptor), and the file is not already open, the file will be opened as a TEXT file in READ mode. Furthermore, if a file name is specified, the file is closed when readdata returns.
Note: The writedata function is the corresponding function for writing numerical data into a file.
Suppose that the example file data contains the following data.
1
50
2
55
70
Read three columns of floating-point numbers from the file data.
readdata⁡data,3
1.,1.,50.,1.,2.,55.,2.,1.,55.,2.,2.,70.
Read three columns as integers.
readdata⁡data,integer,3
1,1,50,1,2,55,2,1,55,2,2,70
Read the first column of data as integers.
readdata⁡data,integer
1,1,2,2
Read the first column of data as floating-point numbers.
readdata⁡data,float
1.,1.,2.,2.
Read the first two columns as integers and the third column as floating-point numbers.
readdata⁡data,integer,integer,float
1,1,50.,1,2,55.,2,1,55.,2,2,70.
See Also
fopen
ImportMatrix
ImportVector
readline
sscanf
writedata
Download Help Document