Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
17
Добавлен:
09.02.2015
Размер:
324.1 Кб
Скачать

If %s is used an element read may cause several matlab matrix

elements to be used, each holding one character. Use %c to read

space characters; the format %s skips all white space.

MATLAB reads characters using the encoding scheme associated with

the file. See FOPEN for more information. If the format string

contains ordinary characters, MATLAB matches each of those characters

with a character read from the file after converting both to the

MATLAB internal representation of characters.

Mixing character and numeric conversion specifications causes the

resulting matrix to be numeric and any characters read to show up

as their numeric values, one character per MATLAB matrix element.

FSCANF differs from its C language namesake in an important respect -

it is "vectorized" in order to return a matrix argument. The format

string is recycled through the file until an end-of-file is reached

or the amount of data specified by SIZE is read in.

Examples:

S = fscanf(fid,'%s') reads (and returns) a character string.

A = fscanf(fid,'%5d') reads 5-digit decimal integers.

See also fopen, fprintf, sscanf, textscan, fgetl, fgets, fread, input.

Overloaded methods:

serial/fscanf

icinterface/fscanf

udp/fscanf

Reference page in Help browser

doc fscanf

<textscan> - Read formatted data from text file.

TEXTSCAN Read formatted data from text file or string.

C = TEXTSCAN(FID,'FORMAT') reads data from an open text file identified

by FID into cell array C. Use FOPEN to open the file and obtain FID.

The FORMAT is a string of conversion specifiers enclosed in single

quotation marks. The number of specifiers determines the number of

cells in the cell array C. For more information, see "Format Options."

C = TEXTSCAN(FID,'FORMAT',N) reads data from the file, using the FORMAT

N times, where N is a positive integer. To read additional data from

the file after N cycles, call TEXTSCAN again using the original FID.

C = TEXTSCAN(FID,'FORMAT','PARAM',VALUE) accepts one or more

comma-separated parameter name/value pairs. For a list of parameters

and values, see "Parameter Options."

C = TEXTSCAN(FID,'FORMAT',N,'PARAM',VALUE) reads data from the

file, using the FORMAT N times, and using settings specified by pairs

of PARAM/VALUE arguments.

C = TEXTSCAN(STR,...) reads data from string STR. You can use the

FORMAT, N, and PARAM/VALUE arguments described above with this syntax.

However, for strings, repeated calls to TEXTSCAN restart the scan from

the beginning each time. (To restart a scan from the last position,

request a POSITION output. See also Example 3.)

[C, POSITION] = TEXTSCAN(...) returns the file or string position at

the end of the scan as the second output argument. For a file, this is

the value that FTELL(FID) would return after calling TEXTSCAN. For a

string, POSITION indicates how many characters TEXTSCAN read.

Notes:

When TEXTSCAN reads a specified file or string, it attempts to match

the data to the format string. If TEXTSCAN fails to convert a data

field, it stops reading and returns all fields read before the failure.

Format Options:

The FORMAT string is of the form: %<WIDTH>.<PREC><SPECIFIER>

<SPECIFIER> is required; <WIDTH> and <PREC> are optional.

<WIDTH> is the number of characters or digits to read.

<PREC> applies only to the family of %f specifiers, and specifies

the number of digits to read to the right of the decimal point.

Supported values for SPECIFIER:

Numeric Input Type Specifier Output Class

------------------------ ----------- ---------------

Integer, signed %d int32

%d8 int8

%d16 int16

%d32 int32

%d64 int64

Integer, unsigned %u uint32

%u8 uint8

%u16 uint16

%u32 uint32

%u64 uint64

Floating-point number %f double

%f32 single

%f64 double

%n double

TEXTSCAN converts numeric fields to the specified output type

according to MATLAB rules regarding overflow, truncation, and the

use of NaN, Inf, and -Inf. For example, MATLAB represents an

Соседние файлы в папке Библиотеки Matlab