dpc525

MATLAB脚本读写二进制文件

使用环境: Windows  + MATLAB 7.5.0

%---------------------------------------------------
%Copyright 
%All right reserved
%File name: write_bin.m
%Author: dpc525
%---------------------------------------------------
%Major funtion:
%      read wave file and play it, then write the data to binary file
%---------------------------------------------------
%Note:  
%---------------------------------------------------
%Modification history
% Mod. Date :2011-05-07
% V0.0:  Initial Revision
%---------------------------------------------------
clear all;
% [f_name p_name] = uigetfile({\'*.wav\',\'WAVE File (*.wav)\'},\'Pick a file\');
% file = strcat(p_name,f_name);
% [x, fs, nbits] = wavread(file, \'native\');
[x,fs, nbits] = wavread(\'1.wav\', \'native\');
wavplay(x, fs);

fp = fopen(\'data.bin\', \'w\', \'native\' );
fwrite( fp, x, \'int16\');
fclose(fp);

读文件

%---------------------------------------------------
%Copyright 
%All right reserved
%File name: read_bin.m
%Author: dpc525
%---------------------------------------------------
%Major funtion:
%      read binary file
%---------------------------------------------------
%Note:  
%---------------------------------------------------
%Modification history
% Mod. Date :2011-05-07
% V0.0:  Initial Revision
%---------------------------------------------------
clear all;
fp = fopen(\'data.bin\', \'r\', \'native\');
y =fread(fp, \'int16=>int16\');  %\'*int16\'
fs = 44100;
wavplay(y,fs);
fclose(fp);

总结:fread(fp, \'int16=>int16\');的第二个参数把人弄的耗好长时间,一直不敢看MATLAB的英文的帮助文档, 先入为主的害怕,逼不得已去读读时候,发现并没有想象中的那么困难,你还会有点喜欢.当你直面现实的时候,也许你会发现路在何方.MATLAB对数字信号处理和自动控制是非常好的搭建原型工具,其脚本语言使用简单方便.一直寻找各种处理数据的工具软件解决问题,可并不总尽人如意.既然自己是程序员,为什么不写一些适合自己的脚本程序了.

分类:

技术点:

相关文章:

  • 2021-11-29
  • 2021-10-26
  • 2021-12-29
  • 2021-09-30
  • 2021-11-22
  • 2021-12-10
  • 2019-01-19
  • 2021-11-17
猜你喜欢
  • 2021-11-11
  • 2021-11-11
  • 2021-09-13
  • 2021-12-27
  • 2021-12-10
  • 2021-09-25
  • 2021-11-07
相关资源
相似解决方案