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.
- 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)"
.
Please see a Fortran book for more information."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. - k
integer vector
Description
writes row-by-row in a formatted file a matrix of real numbers or a column vector
of character strings. If the file already exists, it is overwritten.
Each row of the a
argument
begins 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
History
Version | Description |
2023.1 | write(…) overwrites existing file. |
Report an issue | ||
<< writb | Entrées/Sorties | write4b >> |