Tuesday, August 4, 2009

feof

Test for end-of-file

Syntax

  • eofstat = feof(fid)

Description

eofstat = feof(fid) returns 1 if the end-of-file indicator for the file, fid, has been set, and 0 otherwise. (See fopen for a complete description of fid.)

The end-of-file indicator is set when there is no more input from the file.


ferror

Query MATLAB about errors in file input or output

Syntax

  • message = ferror(fid)
    message = ferror(fid,'clear')
    [message,errnum] = ferror(...)

Description

message = ferror(fid) returns the error string, message. Argument fid is a file identifier associated with an open file (See fopen for a complete description of fid).

message = ferror(fid,'clear') clears the error indicator for the specified file.

[message,errnum] = ferror(...) returns the error status number errnum of the most recent file I/O operation associated with the specified file.

If the most recent I/O operation performed on the specified file was successful, the value of message is empty and ferror returns an errnum value of 0.

A nonzero errnum indicates that an error occurred in the most recent file I/O operation. The value of message is a string that may contain information about the nature of the error. If the message is not helpful, consult the C run-time library manual for your host operating system for further details.




feval

Function evaluation

Syntax

  • [y1,y2,...] = feval(fhandle,x1,...,xn)
    [y1,y2,...] = feval(function,x1,...,xn)

Description

[y1,y2,...] = feval(fhandle,x1,...,xn) evaluates the function handle, fhandle, using arguments x1 through xn. If the function handle is bound to more than one built-in or M-file, (that is, it represents a set of overloaded functions), then the data type of the arguments x1 through xn, determines which function is dispatched to.

[y1,y2...] = feval(function,x1,...,xn) If function is a quoted string containing the name of a function (usually defined by an M-file), then feval(function,x1,...,xn) evaluates that function at the given arguments. The function parameter must be a simple function name; it cannot contain path information.

    Note The preferred means of evaluating a function by reference is to use a function handle. To support backward compatibility, feval also accepts a function name string as a first argument. However, function handles offer the additional performance, reliability, and source file control benefits listed in the section Benefits of Using Function Handles.

Remarks

The following two statements are equivalent.

  • [V,D] = eig(A)
    [V,D] = feval(@eig,A)

Examples

The following example passes a function handle, fhandle, in a call to fminbnd. The fhandle argument is a handle to the humps function.

  • fhandle = @humps;
    x = fminbnd(fhandle, 0.3, 1);

The fminbnd function uses feval to evaluate the function handle that was passed in.

  • function [xf,fval,exitflag,output] = ...
    fminbnd(funfcn,ax,bx,options,varargin)
    .
    .
    .
    fx = feval(funfcn,x,varargin{:});

In the next example, @deblank returns a function handle to variable, fhandle. Examining the handle using functions(fhandle) reveals that it is bound to two M-files that implement the deblank function. The default, strfun\ deblank.m, handles most argument types. However, the function is overloaded by a second M-file (in the @cell subdirectory) to handle cell array arguments as well.

  • fhandle = @deblank;

    ff = functions(fhandle);
    ff.default
    ans =
    matlabroot\toolbox\matlab\strfun\deblank.m
    ff.methods
    ans =
    cell: 'matlabroot\toolbox\matlab\strfun\@cell\deblank.m'

When the function handle is evaluated on a cell array, feval determines from the argument type that the appropriate function to dispatch to is the one that resides in strfun\@cell.


  • feval(fhandle, {'string ','with ','blanks '})
    ans =
    'string' 'with' 'blanks'

No comments:

Post a Comment