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
text函数什么意思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.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。