Data Files
There are two functions that are used to read from, or write to Excel, delimited text, and fixed width text files:
READFILE("file", "type", [colwidths, [rows, [cols, [emptyfill,["decsymb"]]]]])—Returns an array containing the data in file. READFILE is used as a general file input function for Excel, delimited text and fixed width text files
WRITEFILE("file", M)—Writes an Excel file (.xls or .xlsx) or a tab delimited text file such as .txt or.dat from a specified matrix of values M.
Remember that in order to execute, an expression in a PTC Mathcad worksheet must be an assignment or a request for evaluation, as in:
file is a string containing the filename or the full pathname and filename. Non-absolute pathnames are relative to the current working directory.
type is a string that specifies the data format used in the file:
delimited—Data columns separated by a consistent delimiter (default).
The delimiter is automatically selected.
If READFILE does not detect the delimiter, use READTEXT and specify the delimiter explicitly.
fixed—Fixed-column-width data.
Excel—Excel file formats.
colwidths (optional) required for type fixed but omitted otherwise, is an n × 1 column vector specifying the number of characters in each fixed-width column, where n is the total number of columns in the file.
rows (optional) is either a scalar specifying the first row to read from the file, or a 2-element vector specifying the range of rows (inclusive) to read. If this argument is omitted, READFILE reads in every row of the file.
cols (optional) is either a scalar specifying the first column to read from the file, or a 2-element vector specifying the range of columns (inclusive) to read from the file. If this argument is omitted, READFILE reads in every column of the file.
emptyfill (optional) is a string, scalar, or NaN (default), which is substituted for missing entries in the data file.
decsymb (optional) is the decimal symbol to use. You can specify either a "," (comma) or a "." (dot). The default is "." (dot).
M is usually a matrix of r x c elements to be written to the specified file using a single write operation.
If you need to write a single value to the specified file, then you can specify that value in place of argument M.
Use special caution when using a range operator definition as an argument to the WRITEFILE function.
Additional Information
Both rows and cols are indices that start with 1. ORIGIN does not affect the behavior of READFILE.
You can only omit optional arguments from the last argument and back. For example, in READFILE you cannot omit rows and specify cols and emptyfill. If rows is omitted, the value of cols will be used as rows.
Was this helpful?