fwrite

Write data to a binary file

Syntax

y = fwrite ( file_id,x,precision )
y = file_id.fwrite ( x,precision )

Inputs

ArgumentTypeDescriptionUnit
file_idscalarfile identifier from fopenn/a
xaudio or vectordata to write-
precisiontextstring of precision; see below-

Outputs / Return Value

Notes

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