zoukankan      html  css  js  c++  java
  • 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对数字信号处理和自动控制是非常好的搭建原型工具,其脚本语言使用简单方便.一直寻找各种处理数据的工具软件解决问题,可并不总尽人如意.既然自己是程序员,为什么不写一些适合自己的脚本程序了.

  • 相关阅读:
    [LeetCode] 394. Decode String 解码字符串
    [LeetCode] 393. UTF-8 Validation 编码验证
    [LeetCode] Is Subsequence 是子序列
    [LintCode] Maximum Gap 求最大间距
    [LintCode] Nuts & Bolts Problem 螺栓螺母问题
    [LintCode] Kth Smallest Number in Sorted Matrix 有序矩阵中第K小的数字
    [LeetCode] Perfect Rectangle 完美矩形
    LaTex Remove Left Margin 去除左边空间
    LaTex Font Size 字体大小命令
    [LintCode] Continuous Subarray Sum 连续子数组之和
  • 原文地址:https://www.cnblogs.com/dpc525/p/2039820.html
Copyright © 2011-2022 走看看