- •Is the same as the previous syntax, but accepts attribute value pairs,
- •Xlsfinfo Determine if file contains Microsoft Excel spreadsheet.
- •Internet resource
- •Is a string. Message is either a string or a cell array. If it is a
- •Variables and the Windows registry.
- •Zip file access
- •Individual file can be specified relative to the current directory or
- •Tar file access
- •Individual file can be specified relative to the current directory or
- •Gzip file access
- •Individual file can be specified relative to the current directory or
- •Formatted file I/o
- •Icinterface/fgets
- •If %s is used an element read may cause several matlab matrix
- •Integer NaN as zero.
- •If true, textscan treats
- •File opening and closing
- •It on the matlab search path. On unix systems, filename may also start
- •Binary file I/o
- •If the most recent I/o operation was successful, message is empty
- •Indicator in the specified file. Position is indicated in bytes
- •Memory-mapped file support
- •Is correct for platform it's executed on.
- •Is also a valid partial pathname.
- •Serial port support
- •Instrfind will not find an object with a Name property value of
- •Instrfind will not find an object with a Name property value of
- •Timer support
- •Visible timer objects whose property names and property values match
- •Command window I/o
- •In the current directory. The folder contains an m-file for each web service
If true, textscan treats
consecutive delimiters as a single
delimiter. Only valid if you
specify the 'Delimiter' option.
ReturnOnError Determines behavior when TEXTSCAN 1 (true)
fails to read or convert. If true,
TEXTSCAN terminates without error
and returns all fields read. If
false, TEXTSCAN terminates with an
error and does not return an output
cell array.
TreatAsEmpty String(s) in the data file to None
treat as an empty value. Can be a
single string or cell array of
strings. Only applies to numeric
fields.
Whitespace White-space characters ' \b\t'
Examples:
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
The first two elements of C{5} are the maximum values for a 32-bit
unsigned integer, or intmax('uint32').
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 %*1d');
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
For additional examples, type "doc textscan" at the command prompt.
See also fopen, fclose, load, importdata, uiimport, dlmread, xlsread, fscanf, fread.
Reference page in Help browser
doc textscan