Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.5.0 - Français

Change language to:
English - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2024.1.0. This page might be outdated.
See the recommended documentation of this function

Aide de Scilab >> Entrées/Sorties [fichiers] > fprintfMat


writes a matrix in a file

Calling Sequence

fprintfMat(file, M [,format,text])



a string, the pathname of the file to be written


a matrix of real numbers


a character string giving the format. This is an optional parameter, the default value is "%lf".

Supported format: %[width].[precision]type or %type, where:

width: an optional number that specifies the minimum number of characters output;

precision: an optional number that specifies the maximum number of characters printed for all or part of the output field, or the minimum number of digits printed for integer values;

type: lf, lg, d, i, e, f, g (see scanf_conversion for details).


a row (column) vector of strings giving non numerical comments stored at the beginning of the file.


The fprintfMat function writes a matrix in a formated file. Each row of the matrix give a line in the file. If text is given then the elements of text are inserted elementwise at the beginning of the file one element per line.


n = 50;
a = rand(n, n, "u");
fprintfMat(TMPDIR + "/Mat", a, "%5.2f");
a1 = fscanfMat(TMPDIR + "/Mat");

// Lets we create a file Mat1 and insert a comment into it
some_comment = ["This is a comment","This the second line of the comment.","This is the third line of the comment."];
fprintfMat(TMPDIR + "/Mat1", a, "%5.2f",some_comment);

See Also

  • scanf_conversion — mscanf, msscanf, mfscanf conversion specifications
  • mclose — closes an opened file
  • meof — checks if end of file has been reached
  • mfprintf — converts, formats, and writes data to 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 — reads byte or word in a given binary format and converts to a double type
  • mgetstr — reads a character string from a file
  • mopen — opens a file in Scilab
  • mprintf — converts, formats, and writes data to the main scilab window
  • mput — writes byte or word in a given binary format
  • mputstr — writes a character string in a file
  • mscanf
  • 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
<< findfiles Entrées/Sorties [fichiers] fscanfMat >>

Copyright (c) 2022-2024 (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:
Fri Apr 11 14:14:55 CEST 2014