Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2023.0.0 - English


writes byte or word in a given binary format


mput(x [, type, fd])



a vector of floating point or integer type numbers


a scalar: a file descriptor returned by the function mopen. -1 stands for last opened file. Default value is -1.


a string: the binary format used to write all the entries of x.


The mput function writes data to the output specified by the stream parameter fd. Data is written at the position at which the file pointer is currently pointing and advances the indicator appropriately.

The type parameter is a conversion specifier which may be set to any of the following flag characters (with default value "l"):

"l", "i", "s", "ul", "ui", "us", "d", "f", "c", "uc"

for writing respectively a long long, an int (long int), a short, an unsigned long long int, an unsigned int (long int), an unsigned short, a double, a float, a char and an unsigned char. The bytes which are wrote are automatically swapped if necessary (by checking little-endian status) in order to produce machine independent binary files (in little-endian mode). This default swapping mode can be suppressed by adding a flag swap = 0 in the mopen function.

"..l" or "..b"

It is also possible to write in little-endian or big-endian mode by adding a "l" or "b" character at the end of a type specification. For example "db" will write a double in big-endian mode.


filen = 'test.bin';

// force little-endian

// force big-endian

if 1996<>mget(1,'l') then pause,end
if 1996<>mget(1,'i') then pause,end
if 1996<>mget(1,'s') then pause,end
if   98<>mget(1,'c') then pause,end

// force little-endian
if 1996<>mget(1,'ll') then pause,end
if 1996<>mget(1,'il') then pause,end
if 1996<>mget(1,'sl') then pause,end
if   98<>mget(1,'cl') then pause,end

// force big-endian
if 1996<>mget(1,'lb') then pause,end
if 1996<>mget(1,'ib') then pause,end
if 1996<>mget(1,'sb') then pause,end
if   98<>mget(1,'cb') then pause,end


See also

  • mclose — closes opened files
  • meof — checks if end of file has been reached
  • mfprintf — converts, formats, and writes data to a file
  • fprintfMat — writes a matrix in a file
  • mfscanf — reads input from the stream pointer stream (interface to the C fscanf function)
  • fscanfMat — reads a matrix from a text file
  • mget — parses numbers in a binary file and returns them as decimals
  • mgetl — reads lines from an text file
  • mgetstr — reads a character string from a file
  • mopen — opens files in Scilab
  • mprintf — converts, formats, and writes data to the main scilab window
  • mputl — writes strings in a text file
  • mputstr — write a single text in an open file
  • mseek — sets current position in a binary file
  • mtell — Returns the offset of the current byte relative to the beginning of a file
  • mdelete — deletes file(s)
Report an issue
<< mopen Files : Input/Output functions mputl >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Mar 27 11:52:45 GMT 2023