 readdata - Maple Help

read numerical data from text files Calling Sequence readdata(fileID, n) readdata(fileID, format, n) readdata(fileID, format) Parameters

 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 Description

 • 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 $\mathrm{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. Examples

Suppose that the example file data contains the following data.

 1 1 50 1 2 55 2 1 55 2 2 70

Read three columns of floating-point numbers from the file data.

 > $\mathrm{readdata}\left(\mathrm{data},3\right)$
 $\left[\left[{1.}{,}{1.}{,}{50.}\right]{,}\left[{1.}{,}{2.}{,}{55.}\right]{,}\left[{2.}{,}{1.}{,}{55.}\right]{,}\left[{2.}{,}{2.}{,}{70.}\right]\right]$ (1)

Read three columns as integers.

 > $\mathrm{readdata}\left(\mathrm{data},\mathrm{integer},3\right)$
 $\left[\left[{1}{,}{1}{,}{50}\right]{,}\left[{1}{,}{2}{,}{55}\right]{,}\left[{2}{,}{1}{,}{55}\right]{,}\left[{2}{,}{2}{,}{70}\right]\right]$ (2)

Read the first column of data as integers.

 > $\mathrm{readdata}\left(\mathrm{data},\mathrm{integer}\right)$
 $\left[{1}{,}{1}{,}{2}{,}{2}\right]$ (3)

Read the first column of data as floating-point numbers.

 > $\mathrm{readdata}\left(\mathrm{data},\mathrm{float}\right)$
 $\left[{1.}{,}{1.}{,}{2.}{,}{2.}\right]$ (4)

Read the first two columns as integers and the third column as floating-point numbers.

 > $\mathrm{readdata}\left(\mathrm{data},\left[\mathrm{integer},\mathrm{integer},\mathrm{float}\right]\right)$
 $\left[\left[{1}{,}{1}{,}{50.}\right]{,}\left[{1}{,}{2}{,}{55.}\right]{,}\left[{2}{,}{1}{,}{55.}\right]{,}\left[{2}{,}{2}{,}{70.}\right]\right]$ (5)