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

Inputname, mfilename.

Reference page in Help browser

doc function

<global> - Define global variable.

GLOBAL Define global variable.

GLOBAL X Y Z defines X, Y, and Z as global in scope.

Ordinarily, each MATLAB function, defined by an M-file, has its

own local variables, which are separate from those of other functions,

and from those of the base workspace. However, if several functions,

and possibly the base workspace, all declare a particular name as

GLOBAL, then they all share a single copy of that variable. Any

assignment to that variable, in any function, is available to all the

other functions declaring it GLOBAL.

If the global variable doesn't exist the first time you issue

the GLOBAL statement, it will be initialized to the empty matrix.

If a variable with the same name as the global variable already exists

in the current workspace, MATLAB issues a warning and changes the

value of that variable to match the global.

Stylistically, global variables often have long names with all

capital letters, but this is not required.

See also isglobal, clear, clearvars, who, persistent.

Reference page in Help browser

doc global

<persistent> - Define persistent variable.

PERSISTENT Define persistent variable.

PERSISTENT X Y Z defines X, Y, and Z as variables that are local

to the function in which they are declared yet their values are

retained in memory between calls to the function. Persistent

variables are similar to global variables because MATLAB creates

permanent storage for both. They differ from global variables in

that persistent variables are known only to the function in which

they are declared. This prevents persistent variables from being

changed by other functions or from the MATLAB command line.

Persistent variables are cleared when the M-file is cleared from

memory or when the M-file is changed. To keep an M-file in memory

until MATLAB quits, use MLOCK.

If the persistent variable does not exist the first time you issue

the PERSISTENT statement, it will be initialized to the empty matrix.

It is an error to declare a variable persistent if a variable with

the same name exists in the current workspace.

See also global, clear, clearvars, mlock, munlock, mislocked.

Reference page in Help browser

doc persistent

<mfilename> - Name of currently executing M-file.

MFILENAME Name of currently executing M-file.

MFILENAME returns a string containing the name of the most

recently invoked M-file. When called from within an M-file, it

returns the name of that M-file, allowing an M-file to

determine its name, even if the filename has been changed.

P = MFILENAME('fullpath') returns the full path and name of the

M-file in which the call occurs, without the extension.

C = MFILENAME('class') in a method returns the class of the method

(not including the "@"). If called from a non-method, it yields

the empty string.

If MFILENAME is called with any argument other than the above two,

it behaves as if it were called with no argument.

When called from the command line, MFILENAME returns

an empty string.

To get the names of the callers of an M-file use DBSTACK with

an output argument.

See also dbstack, function, nargin, nargout, inputname.

Reference page in Help browser

doc mfilename

<lists> - Comma separated lists.

LISTS Comma separated lists.

Extracting multiple values from a cell array or structure results

in a list of values (as if separated by commas). The comma-separated

lists are valid:

1) by themselves on the command line to display the values,

C{:} or S.name

2) within parentheses as part of a function call,

myfun(x,y,C{:}) or myfun(x,y,S.name)

3) within square brackets as part of a horizontal concatenation

[C{:}] or [S.name]

4) within square brackets as part of a function output list,

[C{:}] = myfun or [S.name] = myfun

5) within braces as part of a cell array construction.

{C{:}} or {S.name}

In all these uses, C{:} is the same as C{1},C{2},...,C{end} and

S.name is the same as S(1).name,S(2).name,...,S(end).name. If

C or S is 1-by-1 then these expressions produce the familiar

single element extraction. Any indexing expression that attempts

to extract more than one element produces a comma separated list.

Hence C{1:5} and S(2:3).name are also comma separated lists.

Comma separated list are very useful when dealing with variable

input or output argument lists or for converting the contents

of cell arrays and structures into matrices.

Examples

C = {1 2 3 4};

A = [C{:}];

B = cat(2,C{:});

[S(1:3).FIELD] = deal(5);

See also varargin, varargout, deal, cell2struct, struct2cell,

num2cell, cat, paren.

<exist> - Check if variables or functions are defined.

EXIST Check if variables or functions are defined.

EXIST('A') returns:

0 if A does not exist

1 if A is a variable in the workspace

2 if A is an M-file on MATLAB's search path. It also returns 2 when

A is the full pathname to a file or when A is the name of an

ordinary file on MATLAB's search path

3 if A is a MEX-file on MATLAB's search path

4 if A is a MDL-file on MATLAB's search path

5 if A is a built-in MATLAB function

6 if A is a P-file on MATLAB's search path

7 if A is a directory

8 if A is a class (EXIST returns 0 for Java classes if you

start MATLAB with the -nojvm option.)

EXIST('A') or EXIST('A.EXT') returns 2 if a file named 'A' or 'A.EXT'

and the extension isn't a P or MEX function extension.

EXIST('A','var') checks only for variables.

EXIST('A','builtin') checks only for built-in functions.

EXIST('A','file') checks for files or directories.

EXIST('A','dir') checks only for directories.

EXIST('A','class') checks only for classes.

If A specifies a filename, MATLAB attempts to locate the file,

examines the filename extension, and determines the value to

return based on the extension alone. MATLAB does not examine

the contents or internal structure of the file.

When searching for a directory, MATLAB finds directories that are part

of MATLAB's search path. They can be specified by a partial path. It

also finds the current working directory specified by a partial path,

and subdirectories of the current working directory specified by

a relative path.

EXIST returns 0 if the specified instance isn't found.

See also dir, what, isempty, partialpath.

Overloaded methods:

inline/exist

fittype/exist

Composite/exist

Reference page in Help browser

doc exist

<mlock> - Prevent M-file from being cleared.

MLOCK Prevent M-file or MEX-file from being cleared.

MLOCK locks the currently running M-file or MEX-file in memory so

that subsequent CLEAR commands do not remove it.

Use the command MUNLOCK or MUNLOCK(FUN) to return the M-file or

MEX-file to its normal CLEAR-able state.

Locking an M-file or MEX-file in memory also prevents any PERSISTENT

variables defined in the file from getting reinitialized.

See also munlock, mislocked, persistent.

Reference page in Help browser

doc mlock

<munlock> - Allow M-file to be cleared.

MUNLOCK Allow M-file or MEX-file to be cleared.

MUNLOCK(FUN) unlocks the M-file or MEX-file named FUN from memory.

so that subsequent CLEAR commands can remove it. These files are,

unlocked by default so that changes to the file are picked up.

Calls to MUNLOCK are only needed to unlock M-files or MEX-files

that have been locked with the MLOCK function.

MUNLOCK, by itself, unlocks the currently running M-file or MEX-file.

See also mlock, mislocked.

Reference page in Help browser

doc munlock

<mislocked> - True if M-file cannot be cleared.

MISLOCKED True if M-file or MEX-file cannot be cleared.

MISLOCKED(FUN) returns logical 1 (TRUE) if the function named FUN

is locked in memory and logical 0 (FALSE) otherwise. Locked M-files

or MEX-files cannot be CLEARED.

MISLOCKED, by itself, returns logical 1 (TRUE) if the currently

running M-file or MEX-file is locked and logical 0 (FALSE) otherwise.

See also mlock, munlock.

Reference page in Help browser

doc mislocked

<precedence> - Operator Precedence in MATLAB.

PRECEDENCE Operator Precedence in MATLAB.

MATLAB has the following precedence for the built-in operators when

evaluating expressions (from highest to lowest):

1. transpose (.'), power (.^), complex conjugate

transpose ('), matrix power (^)

2. unary plus (+), unary minus (-), logical negation (~)

3. multiplication (.*), right division (./), left

division (.\), matrix multiplication (*), matrix right

division (/), matrix left division (\)

4. addition (+), subtraction (-)

5. colon operator (:)

6. less than (<), less than or equal to (<=), greater than

(>), greater than or equal to (>=), equal to (==), not

equal to (~=)

7. element-wise logical AND (&)

8. element-wise logical OR (|)

9. short-circuit logical AND (&&)

10. short-circuit logical OR (||)

See also syntax, arith.

<isvarname> - True for valid variable name.

ISVARNAME True for valid variable name.

ISVARNAME(S) is true if S is a valid MATLAB variable name.

A valid variable name is a character string of letters, digits and

underscores, with length <= namelengthmax, the first character a letter,

and the name is not a keyword.

See also iskeyword, namelengthmax, genvarname.

Reference page in Help browser

doc isvarname

<iskeyword> - Check if input is a keyword.

ISKEYWORD Check if input is a keyword.

ISKEYWORD(S) returns one if S is a MATLAB keyword,

and 0 otherwise. MATLAB keywords cannot be used

as variable names.

ISKEYWORD used without any inputs returns a cell array containing

the MATLAB keywords.

See also isvarname, genvarname.

Reference page in Help browser

doc iskeyword

<javachk> - Validate level of Java support.

JAVACHK Validate level of Java support.

MSG = JAVACHK(LEVEL) returns a generic error message if

the required level of Java support is not available. If it

is, it returns an empty matrix. The following levels of support

exist:

LEVEL MEANING

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

'jvm' The Java Virtual Machine is running.

'awt' AWT components are available.

'swing' Swing components are available.

'desktop' The MATLAB interactive desktop is running.

MSG = JAVACHK(LEVEL, COMPONENT) returns an error message structure that

names the affected COMPONENT if the required level of Java support

is not available. If it is, it returns an empty structure. See example

below.

EXAMPLE:

If you want to write an m-file that displays a Java Frame and want

it to error gracefully if a Frame cannot be displayed, you can do

the following:

error(javachk('awt','myFile'));

myFrame = java.awt.Frame;

myFrame.setVisible(1);

If a Frame cannot be displayed, the error will read:

??? myFile is not supported on this platform.

See also usejava, error.

Reference page in Help browser

doc javachk

<genvarname> - Construct a valid MATLAB variable name from a string.

GENVARNAME Construct a valid MATLAB variable name from a given candidate.

VARNAME = GENVARNAME(CANDIDATE) returns a valid variable name VARNAME

constructed from the string CANDIDATE. CANDIDATE can be a string or a

cell array of strings.

A valid MATLAB variable name is a character string of letters, digits

and underscores, such that the first character is a

letter and the length of the string is <= NAMELENGTHMAX.

If CANDIDATE is a cell array of strings the resulting cell array of

strings in VARNAME are guaranteed to be unique from one another.

VARNAME = GENVARNAME(CANDIDATE, PROTECTED) returns a valid variable

name which is different from any of the list of PROTECTED names.

PROTECTED may be a string or cell array of strings.

Examples:

genvarname({'file','file'}) % returns {'file','file1'}

a.(genvarname(' field#')) = 1 % returns a.field0x23 = 1

okName = true;

genvarname('ok name',who) % returns a string 'okName1'

See also isvarname, iskeyword, isletter, namelengthmax, who, regexp.

Reference page in Help browser

doc genvarname

<classdef> - Define a new class or subclass.

CLASSDEF Define new class or sub-class.

The keyword CLASSDEF denotes the start of a MATLAB class

definition. The MATLAB language defines classes including

double, logical, struct, and cell. These classes control

how values stored in variables behave, including how they

are displayed and allowed forms of indexing.

You can use class definitions to add new classes or add

specialized sub-classes based on existing classes.

CLASSDEF begins a block terminated by END. Only white

space and comments can precede the class definition.

You must place a class definition in a file with the same

name as the class, with a filename extension of '.m'.

Example:

%Create a class named payment, placed in file 'payment.m'

classdef payment

properties

rate;

term;

principle;

end

methods

function obj = payment(r,t,p)

obj.rate = r;

obj.term = t;

obj.principle = p;

end

function disp(obj)

i = obj.rate/(12*100);

payAmt = (obj.principle * i)/(1 - (1+i)^(-obj.term));

s = sprintf('%s%.2f%s%4.2f%s%.2f%s%d%s',...

'Payment per month on a loan of $', obj.principle,...

' at an annual interest rate of ', obj.rate,...

'% is $', payAmt, ' for ', obj.term, ' months.');

disp(s);

end

end

end

See also properties, methods, events.

Reference page in Help browser

doc classdef

Argument handling.

<nargchk> - Validate number of input arguments.

NARGCHK Validate number of input arguments.

MSGSTRUCT = NARGCHK(LOW,HIGH,N,'struct') returns an appropriate error

message structure if N is not between LOW and HIGH. If N is in the

specified range, the message structure is empty. The message structure

has at a minimum two fields, 'message' and 'identifier'.

MSG = NARGCHK(LOW,HIGH,N) returns an appropriate error message string if

N is not between LOW and HIGH. If it is, NARGCHK returns an empty matrix.

MSG = NARGCHK(LOW,HIGH,N,'string') is the same as

MSG = NARGCHK(LOW,HIGH,N).

Example

error(nargchk(1, 3, nargin, 'struct'))

See also nargoutchk, nargin, nargout, inputname, error.

Reference page in Help browser

doc nargchk

<nargoutchk> - Validate number of output arguments.

NARGOUTCHK Validate number of output arguments.

MSGSTRUCT = NARGOUTCHK(LOW,HIGH,N,'struct') returns an appropriate error

message structure if N is not between LOW and HIGH. If N is in the

specified range, the message structure is empty. The message structure

has at a minimum two fields, 'message' and 'identifier'.

MSG = NARGOUTCHK(LOW,HIGH,N) returns an appropriate error message string if

N is not between LOW and HIGH. If it is, NARGOUTCHK returns an empty

matrix.

MSG = NARGOUTCHK(LOW,HIGH,N,'string') is the same as

MSG = NARGOUTCHK(LOW,HIGH,N).

Example

error(nargoutchk(1, 3, nargout, 'struct'))

See also nargchk, nargin, nargout, inputname, error.

Reference page in Help browser

doc nargoutchk

<nargin> - Number of function input arguments.

NARGIN Number of function input arguments.

Inside the body of a user-defined function, NARGIN returns

the number of input arguments that were used to call the

function.

NARGIN(FUN) returns the number of declared inputs for the

M-file function FUN. The number of arguments is negative if the

function has a variable number of input arguments. FUN can be

a function handle that maps to a specific function, or a string

containing the name of that function.

See also nargout, varargin, nargchk, nargoutchk, inputname,

mfilename.

Overloaded methods:

inline/nargin

fittype/nargin

Reference page in Help browser

doc nargin

<nargout> - Number of function output arguments.

NARGOUT Number of function output arguments.

Inside the body of a user-defined function, NARGOUT returns the

number of output arguments that were used to call the function.

NARGOUT(FUN) returns the number of declared outputs for the

M-file function FUN. The number of arguments is negative if the

function has a variable number of output arguments. FUN can be

a function handle that maps to a specific function, or a string

containing the name of that function.

See also nargin, varargout, nargchk, nargoutchk, mfilename.

Overloaded methods:

inline/nargout

fittype/nargout

mbcinline/nargout

Reference page in Help browser

doc nargout

<varargin> - Variable length input argument list.

VARARGIN Variable length input argument list.

Allows any number of arguments to a function. The variable

VARARGIN is a cell array containing the optional arguments to the

function. VARARGIN must be declared as the last input argument

and collects all the inputs from that point onwards. In the

declaration, VARARGIN must be lowercase (i.e., varargin).

For example, the function,

function myplot(x,varargin)

plot(x,varargin{:})

collects all the inputs starting with the second input into the

variable "varargin". MYPLOT uses the comma-separated list syntax

varargin{:} to pass the optional parameters to plot. The call,

myplot(sin(0:.1:1),'color',[.5 .7 .3],'linestyle',':')

results in varargin being a 1-by-4 cell array containing the

values 'color', [.5 .7 .3], 'linestyle', and ':'.

See also varargout, nargin, nargout, inputname, function, lists, paren.

Reference page in Help browser

doc varargin

<varargout> - Variable length output argument list.

VARARGOUT Variable length output argument list.

Allows any number of output arguments from a function. The

variable VARARGOUT is a cell array containing the

optional output arguments from the function. VARARGOUT must be

declared as the last output argument and must contain all the

outputs after that point onwards. In the declaration, VARARGOUT

must be lowercase (i.e., varargout).

VARARGOUT is not initialized when the function is invoked. You

must create it before your function returns. Use NARGOUT to

determine the number of outputs to produce.

For example, the function,

function [s,varargout] = mysize(x)

nout = max(nargout,1)-1;

s = size(x);

for i=1:nout, varargout(i) = {s(i)}; end

returns the size vector and optionally individual sizes. So,

[s,rows,cols] = mysize(rand(4,5));

returns s = [4 5], rows = 4, cols = 5.

See also varargin, nargin, nargout, function, lists, paren.

Reference page in Help browser

doc varargout

<inputname> - Input argument name.

INPUTNAME Input argument name.

Inside the body of a user-defined function, INPUTNAME(ARGNO)

returns the caller's workspace variable name corresponding to

the argument number ARGNO. If the input has no name, for example,

when it is the result of a calculation or an expression such as,

a(1), varargin{:}, eval(expr), etc, then INPUTNAME returns an

empty string.

Example: Suppose the function myfun is defined as:

function y = myfun(a,b)

disp(sprintf('My first input is "%s".' ,inputname(1)))

disp(sprintf('My second input is "%s".',inputname(2)))

y = a+b;

then

x = 5; myfun(x,5)

produces

My first input is "x".

My second input is "".

See also nargin, nargout, nargchk, mfilename.

Reference page in Help browser

doc inputname

<inputParser> - Construct input parser object.

inputParser Construct input parser object

PARSEOBJ = inputParser constructs an empty inputParser object, PARSEOBJ.

This utility object supports the creation of an input scheme that

represents the characteristics of each potential input argument. Once

you have defined the input scheme, you can use the inputParser object

to parse and validate input arguments to functions.

The inputParser object follows handle semantics; that is, methods called on

it affect the original object, not a copy of it. Also note that inputParser

method names begin with a lowercase letter (e.g., addRequired) while

inputParser property names begin with an uppercase letter (e.g., Unmatched).

parse(PARSEOBJ, INPUT1, INPUT2, ...) parses and validates the named inputs

INPUT1, INPUT2, etc.

MATLAB configures inputParser objects to recognize an input scheme.

Use any of the following methods to create the scheme for parsing a

particular function.

addRequired(PARSEOBJ, ARGNAME, VALIDATOR) adds required argument

ARGNAME to the input scheme of object PARSEOBJ. ARGNAME is a single-

quoted string that specifies the name of the required argument.

The optional VALIDATOR is a handle to a function that you write, used

during parsing to validate the input arguments. If the VALIDATOR

throws an error or returns logical 0 (FALSE), the parsing fails and

MATLAB throws an error.

addOptional(PARSEOBJ, ARGNAME, DEFAULT, VALIDATOR) adds optional argument

ARGNAME to the input scheme of object PARSEOBJ. DEFAULT specifies the

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