fwrite
Write data to a binary file
Syntax
y = fwrite ( file_id,x,precision )
y = file_id.fwrite ( x,precision )
Inputs
| Argument | Type | Description | Unit |
|---|---|---|---|
file_id | scalar | file identifier from fopen | n/a |
x | audio or vector | data to write | - |
precision | text | string of precision; see below | - |
Outputs / Return Value
y:yis the number of characters written. If an error occurs,yis null.
Notes
- This function reads a binary file and returns the data read according to
file_idspecified below. xis one of the following: "int8" "uint8" "int16" "uint16" "int32" "uint32" "int64" "uint64" "float" and "double"- If
file_idis audio, the data is scaled before writing to file according tox(e.g., for "int16" the maximum corresponds to 32767). - If
file_idis audio and stereo, the left and right channels are interleaved into the file.
Examples
An audio object of full-scale square wave with alternating 10 positive and 10 negative values written to file as int16
<p style="padding-left: 30px;">x = ones(10)++-ones(10)++ones(10)++-ones(10) // a non-audio vector
x = ...audio // x is now audio
fd=fopen("x.raw","wb")
fd.fwrite(x,"int16") // values of x in the range [-1 1] written to file after scaling with a 16-bit signed integer format (-32768 to 32767)
fd.fclose</p>
Similar signal as above but a non-audio object
<p style="padding-left: 30px;">y = 32767*ones(10)++-32768*ones(10)++32767*ones(10)++-32768*ones(10) // a non-audio vector
fd=fopen("y.raw","wb")
fd.fwrite(y,"int16") // values of y from -32768 to 32767 are written to file as is with a 16-bit signed integer format
fd.fclose</p>
The same files are generated in the above two examples (i.e., the raw file does not have any information about the data type of the object the file was created from).
See Also
Review Status
- Legacy parameter naming does not exactly match current engine metadata and should be reviewed manually.