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

Описание используемых функций MATLAB:

FOPEN Open file.

FID = FOPEN(FILENAME,PERMISSION) opens the specified file with the specified PERMISSION. If the file is opened for reading and it is not found in the current working directory, FOPEN searches down MATLAB's search path. Permission is one of the strings:

'r' read

'w' write (create if necessary)

'a' append (create if necessary)

'r+' read and write (do not create)

'w+' truncate or create for read and write

'a+' read and append (create if necessary)

'W' write without automatic flushing

'A' append without automatic flushing

By default, files are opened in binary mode. To open a text file, add 't' to the permission string, for example 'rt' and 'wt+'. (On Unix and Macintosh systems, text and binary files are the same so this has no effect. But on PC and VMS systems this is critical.)

If the open is successful, FID gets a scalar MATLAB integer, the file identifier, to be used as the first argument to other FileIO routines. If the open was not successful, -1 is returned for FID.

Two file identifiers are automatically available and need not be opened. They are FID=1 (standard output) and FID=2 (standard error).

[FID, MESSAGE] = FOPEN(FILENAME,PERMISSION) returns a system dependent error message if the open is not successful.

[FID, MESSAGE] = FOPEN(FILENAME,PERMISSION,MACHINEFORMAT) opens the specified file with the specified PERMISSION and treats data read using FREAD or data written using FWRITE as having a format given by MACHINEFORMAT. MACHINEFORMAT is one of the following strings:

'native' or 'n' - local machine format - the default

'ieee-le' or 'l' - IEEE floating point with little-endian byte ordering

'ieee-be' or 'b' - IEEE floating point with big-endian byte ordering

'vaxd' or 'd' - VAX D floating point and VAX ordering

'vaxg' or 'g' - VAX G floating point and VAX ordering

'cray' or 'c' - Cray floating point with big-endian byte ordering

'ieee-le.l64' or 'a' - IEEE floating point with little-endian byte ordering and 64 bit long data type

'ieee-be.l64' or 's' - IEEE floating point with big-endian byte ordering and 64 bit long data type.

[FILENAME,PERMISSION,MACHINEFORMAT] = FOPEN(FID) returns the filename, permission, and machineformat associated with the given file identifier. If FID does not exist then an empty string is returned for each variable.

FIDS = FOPEN('all') returns a row vector, the file identifiers for all the files currently opened by the user (but not 1 or 2).

The 'W' and 'A' permissions are designed for use with tape drives and do not automatically perform a flush of the current output buffer after output operations. For example, open a 1/4" cartridge tape on a SPARCstation for writing with no auto-flush:

fid = fopen('/dev/rst0','W')

See also FCLOSE, FREWIND, FREAD, FWRITE, FPRINTF.

FREAD Read binary data from file.

[A, COUNT] = FREAD(FID,SIZE,PRECISION) reads binary data from the specified file and writes it into matrix A. Optional output argument COUNT returns the number of elements successfully read. FID is an integer file identifier obtained from FOPEN. The SIZE argument is optional; if not specified, the entire file is read; if specified, valid entries are:

N read N elements into a column vector.

inf read to the end of the file.

[M,N] read elements to fill an M-by-N matrix, in column order. N can be inf, but M can't.

The precision argument controls the number of bits read for each value and the interpretation of those bits as character, integer or floating point values. Any of the following strings, either the MATLAB versions, or their C or Fortran equivalents, may be used. If not specified, the default is 'uchar'. Numeric values are always returned in double precision arrays.

MATLAB C or Fortran Description

'char' 'char*1' character, 8 bits

'uchar' 'unsigned char' unsigned character, 8 bits

'schar' 'signed char' signed character, 8 bits

'int8' 'integer*1' integer, 8 bits.

'int16' 'integer*2' integer, 16 bits.

'int32' 'integer*4' integer, 32 bits.

'int64' 'integer*8' integer, 64 bits

'uint8' 'integer*1' unsigned integer, 8 bits.

'uint16' 'integer*2' unsigned integer, 16 bits.

'uint32' 'integer*4' unsigned integer, 32 bits.

'uint64' 'integer*8' unsigned integer, 64 bits

'float32' 'real*4' floating point, 32 bits.

'float64' 'real*8' floating point, 64 bits.

The following platform dependent formats are also supported but they are not guaranteed to be the same size on all platforms.

'short' 'short' integer, 16 bits.

'int' 'int' integer, 32 bits.

'long' 'long' integer, 32 or 64 bits.

'ushort' 'unsigned short' unsigned integer, 16 bits.

'uint' 'unsigned int' unsigned integer, 32 bits.

'ulong' 'unsigned long' unsigned integer, 32 bits or 64 bits.

'float' 'float' floating point, 32 bits

'double' 'double' floating point, 64 bits.

The following formats map to an input stream of bits rather than bytes.

'bitN' signed integer, N bits (1<=N<=64).

'ubitN' unsigned integer, N bits (1<=N<=64).

The PRECISION string may contain a positive integer repetition factor of the form 'N*' which prepends one of the strings above, like '40*uchar'.

For example,

fid = fopen('fread.m','r');

F = fread(fid);

s = setstr(F')

opens the file containing this HELP entry, then reads and displays the entire file, using default size = inf and precision = 'uchar'. The resulting length(F) is the number of characters in the file.

[A, COUNT] = FREAD(FID,SIZE,PRECISION,SKIP) includes an optional SKIP argument that specifies the number of bytes to skip after each read. If PRECISION is a bit format like 'bitN' or 'ubitN' SKIP is specified in bits. This is useful for extracting data in noncontiguous fields from fixed length records.

See FOPEN on how to read big- and little-endian files.

See also FWRITE, FSCANF, LOAD, FOPEN.

FCLOSE Close file.

ST = FCLOSE(FID) closes the file with file identifier FID, which is an integer obtained from an earlier FOPEN. FCLOSE returns 0 if successful and -1 if not.

ST = FCLOSE('all') closes all open files, except 0, 1 and 2.

See also FOPEN, FREWIND, FREAD, FWRITE.

CLF Clear current figure.

CLF deletes all children of the current figure with visible handles.

CLF RESET deletes children with visible handles and also resets all figure properties, except Position and Units, to their default values.

PLOT Linear plot.

PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. PLOT(Y) plots the columns of Y versus their index. If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)). In all other uses of PLOT, the imaginary part is ignored.

Various line types, plot symbols and colors may be obtained with PLOT(X,Y,S) where S is a character string made from one element from any or all the following 3 colunms:

y yellow . point - solid

m magenta o circle : dotted

c cyan x x-mark -. dashdot

r red + plus -- dashed

g green * star

b blue s square

w white d diamond

k black v triangle (down)

^ triangle (up)

< triangle (left)

> triangle (right)

p pentagram

h hexagram

For example, PLOT(X,Y,'c+:') plots a cyan dotted line with a plus at each data point; PLOT(X,Y,'bd') plots blue diamond at each data point but does not draw any line.

PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by the (X,Y,S) triples, where the X's and Y's are vectors or matrices and the S's are strings.

For example, PLOT(X,Y,'y-',X,Y,'go') plots the data twice, with a solid yellow line interpolating green circles at the data points.

The PLOT command, if no color is specified, makes automatic use of the colors specified by the axes ColorOrder property. The default ColorOrder is listed in the table above for color systems where the default is yellow for one line, and for multiple lines, to cycle through the first six colors in the table. For monochrome systems, PLOT cycles over the axes LineStyleOrder property.

PLOT returns a column vector of handles to LINE objects, one handle per line.

The X,Y pairs, or X,Y,S triples, can be followed by parameter/value pairs to specify additional properties of the lines.

See also SEMILOGX, SEMILOGY, LOGLOG, GRID, CLF, CLC, TITLE, XLABEL, YLABEL, AXIS, AXES, HOLD, and SUBPLOT.

Windows

BARTLETT BARTLETT(N) returns the N-point Bartlett window.

BLACKMAN BLACKMAN(N) returns the N-point Blackman window.

BOXCAR BOXCAR(N) returns the N-point rectangular window.

CHEBWIN Chebyshev window.

CHEBWIN(N,R) returns the N-point Chebyshev window with R decibels of ripple.

HAMMING HAMMING(N) returns the N-point Hamming window.

HANNING HANNING(N) returns the N-point Hanning window in a column vector.

TRIANG TRIANG(N) returns the N-point triangular window.

KAISER KAISER(N,beta) returns the BETA-valued N-point Kaiser window.

Transforms

FFT Discrete Fourier transform.

FFT(X) is the discrete Fourier transform (DFT) of vector X. If the length of X is a power of two, a fast radix-2 fast-Fourier transform algorithm is used. If the length of X is not a power of two, a slower non-power-of-two algorithm is employed. For matrices, the FFT operation is applied to each column. For N-D arrays, the FFT operation operates on the first non-singleton dimension.

FFT(X,N) is the N-point FFT, padded with zeros if X has less than N points and truncated if it has more.

FFT(X,[],DIM) or FFT(X,N,DIM) applies the FFT operation across the dimension DIM.

For length N input vector x, the DFT is a length N vector X, with elements

N

X(k) = sum x(n)*exp(-j*2*pi*(k-1)*(n-1)/N), 1 <= k <= N.

n=1

The inverse DFT (computed by IFFT) is given by

N

x(n) = (1/N) sum X(k)*exp( j*2*pi*(k-1)*(n-1)/N), 1 <= n <= N.

k=1

The relationship between the DFT and the Fourier coefficients a and b in

N/2

x(n) = a0 + sum a(k)*cos(2*pi*k*t(n)/(N*dt))+b(k)*sin(2*pi*k*t(n)/(N*dt))

k=1

is

a0 = 2*X(1)/N, a(k) = 2*real(X(k+1))/N, b(k) = 2*imag(X(k+1))/N,

where x is a length N discrete signal sampled at times t with spacing dt.

See also IFFT, FFT2, IFFT2, FFTSHIFT.

IFFT Inverse discrete Fourier transform.

IFFT(X) is the inverse discrete Fourier transform of X.

IFFT(X,N) is the N-point inverse transform.

IFFT(X,[],DIM) or IFFT(X,N,DIM) is the inverse discrete Fourier transform of X across the dimension DIM.

See also FFT, FFT2, IFFT2, FFTSHIFT.

Литература: