Google

main
dspblog
cyclic_signals
FFT_interpolation
FFT_interpolation_how_does_it_work
FFT_smoothness_cyclic
discrete_time_reconstruction
discrete_time_reconstruction2
Nyquist_on_the_edge
FFT_delay_special_case
Fourier_reconstruction
pulse_and_Nyquist
FFT_complexError
matlabOctave
matlab_upsampling
matlab_downsampling
FFT_delay
FFT_filter_example
FFT_interpolation_example
FFT_bin_frequencies
fit_signal
FFT_peaksearch_audio_example
matlab_binary_readwrite
Octavesvg
C
FFTW_example
looprecord
SNR
SNR3
SNR_example_96kAudio
SNR_FFT_correlation_example
lua
luagpib
luasplit
luadump
mnoofltk
wxLuaDll
wxLua_loadAsDll
wxLua_HelloWorld
wxLua_simpleButton
wxLua_resourceManagement
wxLua_XMLparser
DSP
IQ_LO
IQ_LO_2
optimum_receiver
DSP_basics
sampleRateChange_terms
dirac_pulse
freqresp_s
zfilter_example
freqresp_z
freqresp_z_sign
misc
zero_forcing_equalizer_example
nonminphase_inverse
periodic_spectrum
lagrange_multipliers
Entropy
RC_chopper
TRex450_setup
EP100
EP100SE
EP100Gremlins
essential_spares
tail_rotor
motoradjustment
blade_balancing
blade_repair
GAUI_SAE12A
Walkera43


valid html (click to verify)



prevupnextdisable ads

Reading / writing binary data from Matlab

Summary

A pair of Matlab / Octave functions to write binary data to file and read it back. Useful when dealing with large amounts of data, for example audio.

“matlab_binary_write” function

Download

matlab_binary_write.m

Usage

matlab_binary_write(filename, data);

Parameters

  • filename: The data file, any extension (for example “.float”)
  • data: A column vector or matrix with one row per data point

Code

function matlab_binary_write(filename, signal)
  fid = fopen(filename, 'wb'); 
  if fid < 0 
    error('failed to open data file for write')
  end
  
  % 1: read as one column
  % interleaving two channels: 2
  fwrite(fid, signal, 'float'); 
  fclose(fid);
  

“matlab_binary_read” function

Download

matlab_binary_read.m

Usage

data=matlab_binary_read(filename, nCols);

Parameters

  • filename: Same datafile as used in matlab_binary_write
  • data: A column vector or matrix with one row per data point

Code

function signal=matlab_binary_read(filename, numCols)
  fid = fopen(filename, 'rb'); 
  if fid < 0 
    error('failed to open data file for write')
  end
  
  signal=fread(fid, [numCols, inf], 'float'); 
  fclose(fid);
  


prevupnextdisable ads

© Markus Nentwig 2007-2008
The content of this page is provided without any warranty and may not be reproduced without permission.

Comments? Questions?

Please send me a mail! mnentwig@elisanet.fi