matlab中的textscan函数

textscan函数使用范例(from help of matlab):

Example 1: Read each column of a text file.
        Suppose the text file 'mydata.dat' contains the following:
            Sally Level1 12.34 45 1.23e10 inf Nan Yes 5.1+3i
            Joe   Level2 23.54 60 9e19 -inf  0.001 No 2.2-.5i
            Bill  Level3 34.90 12 2e5   10  100   No 3.1+.1i
 
        Read the file:
            fid = fopen('mydata.dat');
            C = textscan(fid, '%s%s%f32%d8%u%f%f%s%f');
            fclose(fid);
 
        textscan returns a 1-by-9 cell array C with the following cells:
            C{1} = {'Sally','Joe','Bill'}            %class cell
            C{2} = {'Level1'; 'Level2'; 'Level3'}    %class cell
            C{3} = [12.34;23.54;34.9]                %class single
            C{4} = [45;60;12]                        %class int8
            C{5} = [4294967295; 4294967295; 200000]  %class uint32
            C{6} = [Inf;-Inf;10]                     %class double
            C{7} = [NaN;0.001;100]                   %class double 
            C{8} = {'Yes','No','No'}                 %class cell

            C{9} = [5.1+3.0i; 2.2-0.5i; 3.1+0.1i]    %class double

Example 2: Read a string, truncating each value to one decimal digit.
        str = '0.41 8.24 3.57 6.24 9.27';
        C = textscan(str, '%3.1f %*1c');
        
        textscan returns a 1-by-1 cell array C:
            C{1} = [0.4; 8.2; 3.5; 6.2; 9.2]
 
    Example 3: Resume a text scan of a string.
        lyric = 'Blackbird singing in the dead of night';
        [firstword, pos] = textscan(lyric,'%9c', 1);      %first word

        lastpart = textscan(lyric(pos+1:end), '%s');      %remaining text

Note: For other references, please type 'doc textscan' in command window.

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值