writeMat              package:R.matlab              R Documentation

_W_r_i_t_e_s _a _M_A_T _f_i_l_e _s_t_r_u_c_t_u_r_e

_D_e_s_c_r_i_p_t_i_o_n:

     This function takes the given variables ('...') and places them in
     a MAT file structure, which is then written to a binary
     connection.

     Currently only the MAT version 5 file format is supported.

_U_s_a_g_e:

     ## Default S3 method:
     writeMat(con, ..., matVersion="5", onWrite=NULL, verbose=FALSE)

_A_r_g_u_m_e_n_t_s:

     con: Binary 'connection' to which the MAT file structure should be
          written to. A string is interpreted as filename, which then
          will be opened (and closed afterwards).

     ...: Named variables to be written.

matVersion: A 'character' string specifying what MAT file format
          version to be written to the connection. If '"5"', a MAT v5
          file structure is written. No other formats are currently
          supported.

 onWrite: Function to be called just before starting to write to
          connection. Since the MAT file structure does not contain
          information about the total size of the structure this
          argument makes it possible to first write the structure size
          (in bytes) to the connection.

 verbose: Either a 'logical', a 'numeric', or a 'Verbose' object
          specifying how much verbose/debug information is written to
          standard output. If a Verbose object, how detailed the
          information is is specified by the threshold level of the
          object. If a numeric, the value is used to set the threshold
          of a new Verbose object. If 'TRUE', the threshold is set to
          -1 (minimal). If 'FALSE', no output is written (and neither
          is the R.utils package required). 


     Note that '...' must _not_ contain variables with names equal to
     the arguments 'matVersion' and 'onWrite', which were choosen
     because we believe they are quite unique to this write method.

_V_a_l_u_e:

     Returns (invisibly) the number of bytes written. Any bytes written
     by any onWrite function are _not_ included in this count.

_A_u_t_h_o_r(_s):

     Henrik Bengtsson (<URL: http://www.braju.com/R/>)

_S_e_e _A_l_s_o:

     'readMat'().

_E_x_a_m_p_l_e_s:

     A <- matrix(1:27, ncol=3)
     B <- as.matrix(1:10)

     filename <- paste(tempfile(), ".mat", sep="")

     writeMat(filename, A=A, B=B)
     data <- readMat(filename)
     print(data)

     unlink(filename)

     ## Not run: 
     # When writing to a stream connection the receiver needs to know in
     # beforehand how many bytes are available. This can be done by using
     # the 'onWrite' argument.
     onWrite <- function(x)
       writeBin(x$length, con=x$con, size=4, endian="little");
     writeMat(con, A=A, B=B, onWrite=onWrite)
     ## End(Not run)

