HyperMath

Writing Matrix to a Text File

Writing Matrix to a Text File

Previous topic Next topic No expanding text in this topic  

Writing Matrix to a Text File

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

b = FWrite(fid,M,[delimeter], [format])

Writes matrix contents into a file, separating each column by the specified delimiter.

Option

Description

fid

Handle to an opened file to which the matrix is to be written.

M

The matrix whose content is to be written.

delimiter

An optional string specifying the delimiter.  Defaults to space delimited.  This must be specified if the output format is also specified.

format

An optional string specifying the C-style format.  The supported format is described below.  The default format is "%0.5g".

b

A Boolean.  True (1) on success.

The format string has the form:

% [width] [.precision]type

Option

Description

type

A required character field that specifies how the associated argument is to be interpreted.  The options include a character, string, or number.  It can be any of the following:

 

f

Double precision.

 

e

Double precision in exponential notation.

 

g

Double or exponential notation, depending on the magnitude.

width

An optional integer that pads the output with leading spaces so that it is at least the width number of characters wide.

precision

An optional integer.  For %f and %e, it causes the decimal portion of the output to be expressed in at least precision digits.

For %g, it causes the maximum number of significant digits to be this precision.

fid = Open(‘c:/test.txt’,’w’) // Open a file in write mode

M = [1,2;3,4];

FWrite(fid,M,",", "%1.0e"); // Writes the matrix separating each column by a comma in exponential format

Close(fid); // close the file