fwrite

Parent Previous Next

fwrite

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

Write data to a binary file

arg

type

Description

Unit or Value scale

file_id

SCAL

file identifier from fopen


x

AUD or VCT

data to write


precision

TXT

string of precision; see below


Outputs

  • y is the number of characters written. If an error occurs, y is null.

Notes

  • This function reads a binary file and returns the data read according to file_id specified below.
  • x is one of the following: "int8" "uint8" "int16" "uint16" "int32" "uint32" "int64" "uint64" "float" and "double"
  • If file_id is audio, the data is scaled before writing to file according to x (e.g., for "int16" the maximum corresponds to 32767).
  • If file_id is 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

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

  • Similar signal as above but a non-audio object

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

  • 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

fopen | fclose | fread

Created with the Personal Edition of HelpNDoc: Easily create EBooks