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


write

writes real numbers or strings in the console or in a formatted file

Syntax

write(file_desc, a)
write(file_desc, a, format)
write(file_desc, a, k, format)

Arguments

file_desc

Either

  • a character string specifying the file name. Trying to overwrite an existing file will yield an error.
  • or the integer id of a file opened with file(…) (see file). Using %io(2) will write in the console.

This function can not open a UTF filename. In this case, please uses mopen.

a

Matrix of real numbers, or column of character strings.

format

character string specifying a "Fortran" format. It must begin with a left parenthesis and end with a right one. The format must be about only one type of input data. It can't mix placeholders for real numbers and for strings.

Format examples : "(1x,e10.3,5x,3(f3.0),1x,i4)" , "(10x,a20)".

"x": white space. "5x" = 5 white spaces
"a": string. "a20" = 20 first characters of the input string.
"i": print as integer
"f": real number
"e": real number in exponential form.
"(…)": group. 3(…) = iterate 3 times the group.
Please see a Fortran book for more information.

k

integer vector

Description

writes row-by-row a real matrix or a column vector of character strings in a formatted file. Each row of the a argument begin in a new line of file_desc file. Depending on format a given row of the a argument may be written in more than one line of file_desc file.

Direct access files : x=write(file_desc,a,k,format). Here k is the vector of records (one record by row, i.e. m=prod(size(k))

write(%io(2),....) writes on Scilab's console. Note that in this case format should produce one output line per matrix row. If this constraint is not verified, unpredictable behavior could happen.

Examples

if getos() == 'Windows' then unix('del asave');
else unix('rm -f asave'); end
A = rand(5,3);
write('asave',A);
A = read('asave',5,3);

write(%io(2),A,'('' | '',3(f10.3,'' | ''))')
write(%io(2),string(1:10))
write(%io(2),strcat(string(1:10),','))
write(%io(2),1:10,'(10(i2,3x))')

if getos() == 'Windows' then unix('del foo');
else unix('rm -f foo'); end
write('foo',A)

See also

  • save — Saves some chosen variables in a binary data file
  • writb — fortran file binary write
  • file — file management
  • fileinfo — provide information about some files of any type
  • print — prints variables in a file
  • mfprintf — converts, formats, and writes data to a file
  • mprintf — converts, formats, and writes data to the main scilab window
  • fprintfMat — writes a matrix in a file
Report an issue
<< writb Entrées/Sorties write4b >>

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 10:12:38 GMT 2023