How to set up smartphones and PCs. Informational portal

Matlab variable types. Programming M functions

In the MATLAB system, there is a special kind of variables whose value, with the exception of the ans variable, cannot be changed. These variables are called system variables. They are meant for more effective work during calculations, as well as for displaying messages by the system in case of incorrect statement of the problem by the user. The table lists the system variables used in MATLAB.

MATLAB system variable notation

Complex numbers

In MATLAB system complex numbers, just like real ones, have type double. Therefore, there is no need for a separate marking marking work with complex numbers. The record is made as follows: 3+7i; -7.1+0.831E+2*i; 5-3j. The example shows that one of the letters can be used to designate the imaginary unit: i or j. By default, MATLAB uses the letter i .

Below is an example of calculating the square root of -1

>>b=sqrt(a)

For complex numbers, you can use the same functions as for real numbers, except for the obvious cases when the function cannot have a complex argument. For example, the function rem (x,y) calculates the remainder of x divided by y, so using a complex number as its argument will result in an error:

>> a=2+3*i;

>> rem(a,3)

Error using ==> rem

Arguments must be real.

Along with this, there are also a number of functions that apply only to complex variables.

Functions of complex variables

For example:

>> abs(2+3i)

>>conj(2+3i)

2.0000 - 3.0000i

>> isreal(x)

In the last example, the isreal function returned the number 0 because variable x is not real.

5. Visibility of variable names and function names.

Local and global variables. The function has its own space of variables, isolated from the workspace of the MATLAB system. Therefore, if a variable with a name, for example, varName1, was defined in the MATLAB command window before calling the M-function, then you cannot count on the fact that the variable in the function body with the same name already has some value. This is a completely different variable (although it has the same name varName1) and is located in the machine's memory in a different memory area.

Variables that are used in the body of an M-function and do not match the names of the formal parameters of this function are called local. In another way they say that they are visible only within the M-function. From the outside they are not visible (not achievable). Variables defined in the MATLAB command window are not visible inside the function - they are external to the function and are not visible in it.

Likewise, variables local to some function are not visible inside another M-function.

One of the channels for transferring information from the command window of the MATLAB system to an M-function and from one function to another is the mechanism of function parameters. Another such mechanism is global variables.

In order for the MATLAB system workspace and several M-functions to share a variable with some name, it must be declared globally everywhere using keyword global. For example, the glVarS variable involved in workspace calculations and in the FuncWithGlobVar function is the same variable (single memory location) everywhere - so it can be used in the function without additionally assigning it any value:

Since global variables have a "global" scope, in order not to accidentally (by mistake) redefine it somewhere, it is desirable to give such variables more mnemonic (longer and more meaningful) names.

Now consider the question of the visibility of function names. If we have saved a function with a certain name in a file with the same name and extension m, and in addition, if the MATLAB system knows the path to this file on disk, then this function can be called both from the command window and from other functions.

However, in the text of an M-function, definitions of several functions can be placed, and only one of them can have the same name as the file name. It is this function that will be visible from the command window and other functions. All other functions will be internal - only functions from the same file can call them.

For example, if the ManyFunc.m file contains the following text

function ret1 = ManyFunc(x1, x2)

ret1 = x1 .* x2 + AnotherFunc(x1)

function ret2 = AnotherFunc(y)

ret2 = y .* y + 2 * y + 3;

consisting of two function definitions named ManyFunc and AnotherFunc, then only the ManyFunc function can be called from outside. In another way, we can say that only functions with names that match the names of M-files are visible from the outside. The remaining functions must be called by this function and other internal functions.

3.3. Execution of M-functions. Argument lists. Argument types. Data types

M function can be called from command line MATLAB system or from other M-files, be sure to specify all the necessary attributes - input arguments in parentheses, output arguments in square brackets.

Name assignment. When a new name appears, MATLAB checks:

  1. Whether the new name is the name of a variable.
  2. Is this the name of a subfunction, that is, a function that is located in the same M-file and is called.
  3. Is it the name of a private function located in the private directory. This directory is only accessible by M-files placed one level up.
  4. Is it the name of a function in the MATLAB system path. In this case, the system uses the M-file that occurs first in the access path.

In case of duplicate names, MATLAB uses the first name according to the 4-level hierarchy above. It should be noted that in MATLAB 5 it is allowed to redefine a function according to the rules of object-oriented programming.

Function call. At M-function call, MATLAB translates the function into pseudocode and loads it into memory. This avoids re-parsing. The pseudocode remains in memory until the clear command is used or the session ends.

Allowed following modifications clear commands:

This command does parsing M-file average.m and saves the resulting pseudo-code in a file named average.p. This avoids re-parsing during a new session. Since parsing is very fast, using the pcode command has almost no effect on the speed of its execution.
The use of the P-code is useful in two cases:

  • when to parse a large number M-files required for rendering graphic objects in development applications GUI user; in this case, the use of the P-code provides a significant speedup;
  • when the user wants to hide the algorithms implemented in the M-file.

Argument passing rules. From the programmer's point of view, the MATLAB system passes an argument by its value. In fact, only those arguments that are changed during the operation of this function are passed by value. If the function does not change the value of the argument, but only uses it for calculations, then the argument is passed by reference, which optimizes memory usage.

Feature workspaces. Each M-function is allocated an additional memory area that does not overlap with the work area of ​​the MATLAB system. This area is called the work area of ​​the function. Each function has its own workspace.

When working with the MATLAB system, you can only access variables located in the workspace of the system or in working area functions. If a variable is declared global, then it can be considered as if it belongs to several work areas.

Checking the number of arguments. The nargin and nargout functions allow you to determine the number of input and output arguments of the called function. This information can later be used in condition statements to change the course of calculations.

Example:

function c = testarg1(a,b)
if(nargin == 1)
c = a.^2;
elseif(nargin == 2)
c = +b;
end

Given a single input argument, the function calculates the square of the input variable; when given two arguments, an addition operation is performed.

Consider more complex example- selection of a part of a character string before the separator, which can be a space or any other character. When given a single input argument, the function must extract the part of the string up to the delimiter, which defaults to a space; and all spaces at the beginning of the line are removed. When two arguments are specified, the delimiter character must be specified as the second argument.

This function is formatted as the M-function strtok, which is located in the strfun directory.

The function must have at least one input argument

If there is only one input argument, then a space is used as a separator.

Determine the beginning of the selected substring

Determine the end of the selected substring

Selecting the rest of a line

Note that the order of the arguments in the output list is important. If no output argument is specified when calling an M-function, the first argument is output by default. For the formation and output of subsequent arguments, it is required to organize an appropriate call to the M-function.

Argument lists.

The varargin and varargout functions allow you to pass an arbitrary number of input and output arguments. The MATLAB system packs all the specified input and output arguments into a cell array. Each cell can contain any type and any amount of data.

Example
The testvar function accepts any number of two-element vectors as input arguments and displays the lines connecting them.

function testvar(varargin)

for i = 1:length(varargin)
x(i) = varargin(i)(1);
y(i) = varargin(i)(2);
end

xmin = min(0, min(x));
ymin = min(0, min(y));
axis()
plot(x,y)

Thus, the testvar function can work with input lists of different lengths.

Example:

testvar(, , , , , )
testvar([-1 0], , , )

Formation of the input array varargin. Since the varargin list stores the input arguments in a cell array, the cell indexes must be used to retrieve the data. A cell index has two components:
- index in curly brackets;
- index in parentheses.

Example:

y(i)=varargin(i)(2);
Here, the index in curly brackets (i) indicates the address of the i-th cell of the varargin array, and the index in parentheses (2) points to the second element in the cell.

Forming the output array varargout. With an arbitrary number of output arguments, they must be packed into a varargout cell array. To determine the number of output arguments to a function, use the nargout function.

Example
The following function takes as input a two-column array, where the first column is a set of x-coordinate values ​​and the second is a set of y-coordinate values. The function splits the array into individual vectors, which can be passed to the testvar function as inputs.

function = testvar2(arrayin)
for i = 1:nargout
varargout(i) = arrayin(i, :);
end

assignment operator in for loop uses cell array assignment syntax. The left side of the assignment statement uses curly braces to indicate that the array string data is being assigned to the cell.

The following statements can be used to call the testvar2 function:

a = ";
= testvar2(a)

p1 = 16
p2 = 2 7
p3 = 3 8
p4 = 4 9
p5 = 5 0

Using cell arrays in argument lists. The varargin and varargout arguments must come last in their respective argument lists. When called function arguments, preceding varargout must be evaluated inside the function.

Example
The function headers below show correct use varargin and varargout lists:

function = example1(a,b,varargin)
function = example2(x1,y1,x2,y2,flag)

Variable types.

Local and Global Variables. Using variables in an M-file is no different from using variables on the command line, as follows:

  • variables do not require declaration; before assigning a value to a variable, you must make sure that all variables on the right side of the value are assigned;
  • any assignment operation creates a variable, if necessary, or changes the value of an existing variable;
  • variable names begin with a letter followed by any number of letters, numbers, and underscores; MATLAB distinguishes between upper and lower characters lower case;
  • variable name must not exceed 31 characters. More precisely, the name can be longer, but MATLAB only considers the first 31 characters.

Usually, each M-function specified in the form of an M-file has its own local variables, which are different from other function and workspace variables. However, if multiple functions and a workspace declare a variable global, then they all use a single copy of that variable. Any assignment to this variable is propagated to all functions where it is declared global.

Example.
Suppose it is required to investigate the influence of the coefficients a and b for the predator-prey model described by the Lotke-Volterra equations:

Let's create an M-file lotka.m:

function yp = lotka(t, y)
%LOTKA of the Lotke-Volterra equation for the predator-prey model

global ALPHA BETA
yp = ;

Then, through the command line, enter the operators:

global ALPHA BETA
ALPHA = 0.01;
BETA = 0.02;
= ode23("lotka2",,);
plot(t,y)

The global command declares the ALPHA and BETA variables global and therefore available in the lotka.m function. Thus, they can be changed from the command line, and new solutions will be obtained without editing the M-file lotka.m.

To work with global variables, you must:

  • declare the variable as global in every M-function that needs this variable. For a workspace variable to be global, you must declare it as global from the command line;
  • in each function, use the global command before the first occurrence of the variable; it is recommended to specify the global command at the beginning of the M-file.

Global variable names are usually longer and more meaningful than local variable names, and are often used capital letters. This is optional but recommended to ensure readability of MATLAB language code and to reduce the chance of accidentally redefining a global variable.

Special variables. Some M-functions return special variables that play important role when working in the MATLAB system environment:

ans Last result; if the output variable is not specified, then MATLAB uses the ans variable.
eps Floating point precision; is determined by the length of the mantissa and for PC eps = 2.220446049250313e-016
realmax Maximum number floating point representable in a computer; for PC realmax = 1.797693134862316e+308.
realmin The smallest floating point number that a computer can represent; for PC realmin = 2.225073858507202e-308.
pi Special variable for number p: pi=3.141592653589793e+000.
i, j Special variables to denote the imaginary unit
inf Special variable to represent the infinity symbol?
NaN A special variable for designating an undefined value - the result of operations like: 0/0, inf/inf.
computer A special variable to indicate the type of computer being used; for PC - PCWIN.
flops A special variable to indicate the number of floating point operations.
version A special variable for storing the version number of the MATLAB system being used.

The corresponding M-functions that generate these special variables are found in the elmat directory and are supported by an online help.

Data types.

MATLAB defines six base types data, each of which is a multidimensional array. The six classes are double, char, sparse, uint8, cell, and struct. The two-dimensional versions of these arrays are called matrices, which is where MATLAB gets its name Matrix Lab.

The diagram of belonging of one or another object of the MATLAB system to one of the classes has the following form (Fig. 3.1):

It is likely that most of the time you will only be dealing with two of these data types: an array of doubles (double) and an array of characters (char), or just a string. This is due to the fact that all calculations in the MATLAB system are performed in double precision and most of the functions work with arrays of double precision numbers or strings.

Other data types intended for such special applications, like working with sparse matrices (sparse), image processing (uint8), working with large arrays (cell and struct).

You cannot set the variable type to numeric or array. These types are called virtual and serve only to group variables that share common attributes.

The uint8 type is designed to store data efficiently in memory. Only basic indexing and resizing operations can be applied to data of this type, but no mathematical operation can be performed. To do this, such arrays must be converted to the double type.

Create your own types and add methods to built-in types. The table below contains the seventh data type, UserObject. MATLAB language allows you to create your own data types and work with them in the same way as built-in types.

For built-in data types, you can override a method in the same way as you can override an object. For example, to specify a sort operation for an array of type uint8, you would create a method (sort.m or sort.mex) and place it in the @uint8 special directory.

The following table describes the data types in more detail.

Class Example Description
Double [ 1 2; 3 4]
5+6i
Numeric array double precision (this is the most common variable type in the MATLAB system
Char "Hey" Character array(each character is 16 bits long), often referred to as a string.
Sparse Speye(5) sparse matrix double precision (2D only). The sparse structure is used to store matrices with a small number of non-zero elements, which makes it possible to use only a small part of the memory required to store a full matrix. Sparse matrices require the use of special methods for solving problems.
cell (17 "hello" eye (2)) Cell array. The elements of this array contain other arrays. Cell arrays allow you to merge related data, maybe various sizes, into a single structure.
Struct A.day = 12; A.color="Red"; A.mat = magic(3); Record array. It includes the field names. The fields themselves can contain arrays. Like cell arrays, record arrays combine related data and information about it.
Uint8 Uint8(magic(3)) Array of 8-bit unsigned integers. It allows you to store integers between 0 and 255 in 1/8 of the memory required for a double precision array. None mathematical operations for these arrays are not defined.
UserObject inline("sin(x)") User defined data type.

Diagram Description. The connecting lines in the diagram (Fig. 3.1) determine whether a particular data type belongs to one or more classes.

Example
A matrix of type sparse also has types double and numeric. Operators
isa(S",sparse")
isa(S",double")
isa(S",numeric")

return the values ​​1(true), i.e. S is a double-precision numeric sparse matrix.

Note that the type is array - the array is at the top of the diagram. This means that all MATLAB system data are arrays.

Each data type can be associated with its own functions and processing operators, or in other words, methods. Child types data located in the diagram below the parent type are also supported by the methods of the parent. Therefore, an array of type double is supported by the methods used for type numeric.

The table shows some of these methods:

Class Method
array Calculation of size (size), length (length), dimensions (ndims), array union (), transpose (transpose), multidimensional indexing (subsindex), reshape (reshape) and permute (permute) dimensions of a multidimensional array.
cell array Indexing using curly braces (e1,…,en) and separating list items with commas.
String Char String Functions(strcmp, lower), automatic conversion to type double to apply the methods of the double class.
Double Arithmetic and logical operations, mathematical functions, functions of matrices.
Numeric Search (find), processing of complex numbers (real, imag), formation of vectors, selection of rows, columns, array subblocks, scalar expansion.
Sparse Operations on sparse matrices.
Array of Struct records Access to the contents of the .field field (the list element separator is a comma).
Uint8 Storage operation (most commonly used with PPP image processing toolbox)
UserObject User Defined

Empty arrays. Early versions MATLAB systems allowed a single form of an empty array of size 0x0, denoted as . MATLAB 5 supports arrays that have one but not all of their dimensions equal to zero, that is, arrays with dimensions 1x0, 10x0x20, or defined as empty.

Square brackets continue to denote the array 0x0. Empty arrays of other sizes can be created using the zeros, ones, rand, or eye functions. For example, to form an empty array of size 0x5, you can use the assignment operator
E = zeros(0.5).

The main purpose of empty arrays is that any operation that is defined on an array (matrix) of size m × n determines the correct result for the case when m or n is zero. The size of the array (matrix) of the result must correspond to the value of the function calculated at zero.

For example, the operator
C=
requires arrays A and B to have the same number of rows. Thus, if array A has size m x n and B is m x p, then C is an array of size m x (n+p). The result will be correct if any of the parameters m, n or p is zero.

Many operations in the MATLAB system create a row or column vector. In this case, the result can either be an empty row vector
r = zeros(1, 0),
or an empty column vector
C = zeros(0, 1).

MATLAB 5 supports the MATLAB 4 system rules for if and while statements. For example, conditional operator type
if A, S1, else, S0, end
executes the S0 statement when A is an empty array.

Some MATLAB functions such as sum, prod, min and max reduce the dimension of the result: if the argument is an array, then the result is a vector; if the argument is a vector, then the result is a scalar.

For these functions, with an empty input array, the following results are obtained:
sum() = 0 ;
prod() = 1 ;
max() = ;
min() = .

Like other programming languages, MATLAB has the ability to work with variables. Variables are named objects that store some kind of data. Variables can be numeric, vector, or character, depending on the type of data they store. The variable has a name called identifier. The data can change its values, the identifier remains the same.

When choosing a name for a variable, be guided by the following rules.

■ A variable name can be any number of characters, but only the first 63 characters are remembered and identified (the name lengthmax function returns this number as the maximum possible number of characters in the variable name).

■ A variable name must always begin with a letter and can contain any combination of letters, numbers, and underscores (_).

■ It is not allowed to use spaces in variable names and Special symbols(such as +, -,*,/).

■ The variable name must not be the same as the names of other MATLAB variables, functions, procedures, and system variables.

■ Variable names distinguish between lowercase and capital letters(i.e. Abc and aBc are different names).

Before using any variable, you can check whether the name chosen for it is valid. For this, it is applied next function:

isvarname variable_name

where variable_name is the name of the variable you want to verify is correct. This function returns 1 if the name is valid and 0 otherwise. For example, the name 12_abc_3 8 is invalid because it starts with a number, so given function returns 0.

>> isvarname 12_abc_3 8

There are several reserved variable names in MATLAB. Variables with such names are called systemic. They are set after system boot and can be used in mathematical expressions. System variables can be overridden, i.e. they can be assigned other values ​​if necessary.

The main MATLAB system variables are listed below.

■ i , j - imaginary unit (square root of -1) used to specify the imaginary part of complex numbers.

■ pi - number π (π = 3.141592653589793).

■ eps - error of operations on floating point numbers, ie. the interval between the number 1.0 and the next nearest floating point number (equal to 2.2204e-16, or 2-52).

■ ans - result last operation without an assignment sign.

■ inf - designation of machine infinity.

■ NaN - short for words Not a Number (not a number), used to denote an indeterminate result (for example, 0/0 or Inf /Inf).

■ realmin - minimal modulo real number (2 .22 51e-308, or 2 -1022).

■ realmax - maximum modulo real number (1.7977e+308, or 21023).

In MATLAB, unlike other programming languages, variable types are not declared in advance. It is enough to assign a value to the variable certain type. For example, to assign a variable but value 5, enter the expression on the command line but=5 (as assignment operator equals sign is applied) and press the key , after which the program will immediately return the value of this variable.

>> but=5

As you can see, in this case MATLAB program there is no need to assign the variable ans to represent the result, because the variable is set but.

If you do not want the value to be immediately displayed on the screen after assigning a value to a variable, end the assignment operation with a semicolon (;) and only then press .

The effect of the semicolon extends beyond assignments. If you specify this character at the end of any expression entered on the command line, then the result of its evaluation will not be immediately displayed on the screen. Instead, you will be prompted for the next command (). You can assign a number, an arithmetic expression, a character string (enclosed in apostrophes), or a character expression to a variable.

To increase the efficiency of the program, you may need to erase from the computer's memory either all the variables used in the current session, or only some of them. To clear memory from variables in MATLAB, the clear function is used, which has the syntax:

· clear – destruction of all variables;

· clear x - destruction of the variable x;

clear a b c - the destruction of a family of variables ( the arguments to the clear command immediately follow the command name and are separated by spaces).

To erase all the contents of the MATLAB command window, use the c1c command. After choosing this command, only the information entered in the command window will be deleted, but the values ​​of workspace variables will not be affected. This can be checked by typing the name of any of the variables defined in the current session at the command line.

End of work -

This topic belongs to:

Special characters and their purpose

The language of communication with matlab .. symbols and operators of the language .. language operators are symbols of operations on data called operands in matlab, all generally accepted ..

If you need additional material on this topic, or you did not find what you were looking for, we recommend using the search in our database of works:

What will we do with the received material:

If this material turned out to be useful for you, you can save it to your page on social networks:

1. ELEMENTS OF M-LANGUAGE MATLAB

The elements in the M-language used to control the computational process in MATLAB are constants, variables, functions, commands, and control structures. These elements may be various compounds with the help of special connecting elements, are used both in the command line and in programs.

1.1. CONSTANTS BMATLAB

A constant in MATLAB is information that does not change during the entire communication session. Constants are either user-defined (user-defined) or system-defined (system-defined). User constants are set by the user and are used once - at the moment they are mentioned in the executable command line. For example, 16, -38.654, -1.e-23, 1+2i, "This is a symbol constant".

System constants are permanently defined in the system and have special notations by which they are referred to, e.g. pi (=3.1416), eps (=2.2204e-016), realmin (=2.2251e-308), realmax (=1.7977e+308 ), i, j (jºi).

1.2. VARIABLES INMATLAB

A variable in MATLAB is defined by an identifier, a type, a location in the computer's memory. To define a variable in MATLAB, you must select the identifier (name) of the variable (starts with latin letter, hereinafter - Latin letters, numbers, special characters) and use this variable in a command line statement that sets the value of the variable (simple assignment, reference to some functions, etc.).

  1. Numeric variables: ordinary (real) or complex numbers, vectors, matrices and multidimensional arrays. 8 bytes are allocated for a real number, 16 for a complex number. Integer and real numbers do not differ.

A) real numbers

A=2 A=2.0 B=-143.298 C=1.23e-2

B) complex numbers

Q=1+3i r=-4.6-7.45i S=2+5j

real(Q) – real part of the complex number,

imag(Q) – imaginary part of the set number,

abs(Q) – absolute value of the set number,

conj(Q) – conjugate complement number,

angle(Q) – value of the phase (angle) of the set number in radians.

C) vectors

row vectors

a=1:3:10 b= c=linspace(13,53,5)

column vectors

aa=a’ bb= cc= linspace(13,53,5)’ dd=(15:45)’

for vectors with complex components: if y is a complex vector, then y.' is a column vector with the same components, and y' is a column vector with conjugate components.

D) matrices: M(i,j) – element of the i -th row and j -th column; M(k) - kth element matrix stretched into a column.

A= ---à 1 2

A(2,2) (=4) A(3) (=2) -à A = (1 3 2 4)

A(3,4)=10 ---à 1 2 0 0

size(A) (=) =size(A) (m=3, n=4)

A=A(:) -à pull into a column - the matrix becomes a vector!

reshape(A,3,4) -à turns the vector back into a 3x4 matrix

A(,:)= -à removes the 1st and last rows from the matrix

A(:,)= à removes all columns except the last one

Some special matrices:

eye(m,n) - ones on the main diagonal, the rest are zeros (eye(m) is the mxm square identity matrix)

ones(m,n) – matrix of ones

zeros(m,n) – matrix of zeros

rand(m,n) – mxn matrix filled with random numbers from 0 to 1

C=round(1+100*rand(10,10)) is a 10x10 matrix filled with random integers from 1 to 100.

Simple matrix operations:

diag(A) is a vector of elements on the main diagonal of matrix A,

diag(diag(A)) is a square diagonal matrix with diag. elements, like A, and zeros.

triu(A) tril(A) is a matrix with upper (upper) or lower (lower) parts from A, padded with zeros.

  1. Symbolic variables

cvb='Moscow is the Capital of Russia'

The character string is limited to single apostrophes (on the key with the Russian letter "e") and highlighted in color.

Each character occupies 2 bytes and is treated as separate element character row vector. So if we set the transposition operation cvb’ , we get a column vector with 31 elements.

You can convert character variables to numbers and vice versa.

Usually they are used when displaying results, graphs, inscriptions, messages.

Variable control.

Method 1 - in the Workspace window

Method 2 - the who command - gives a list of defined present moment time variables.

3 way - the whos command - gives more full information about variables (Name Size Bytes Class)

Memory cleaning.

clear - complete clearing of all variables (or clear variables)

clear var1,var2,… - clearing individual variables var1,var2,….

1.3. FUNCTIONS INMATLAB

Functions in MATLAB are programs that perform some common operation on data. To perform these operations and obtain the required results, it is enough to specify the name of the function and, possibly, to specify some initial data. Thus, 3 concepts are associated with the concept of a function here (as in any other language): the name of the function, the set of input data (varargin) and the set of output data (varargout). In addition, the concepts of the number of input parameters (nargin) and the number of output parameters (nargout) are defined.

Functions in MATLAB are divided into user-defined (defined, developed by the user) and system (defined, specified in the system that do not require programming). About how to create custom functions, will be discussed when considering programming issues. Once created and debugged, a user function is no different from a system function.

System functions are divided into built-in and library functions. Library functions are stored in the system in the form of M-language programs written in files with a name that matches the name of the function and with the *.m extension. The texts of these programs are available for viewing by users (the \toolbox\matlab\ directory in the MATLAB installation location). For example, you can open an m-file with a function for calculating the value of the decimal logarithm (\toolbox\matlab\elfun\log10.m) for viewing. When executed, the statements of these programs are first translated into instructions executive system computer (interpreted) and then executed. Built-in functions are stored in the system in a compiled form, do not require translation and, due to this, are executed faster than library ones. The system directory for such functions stores files named similarly to library ones, but containing only comments on the use of functions. For example, you can open a file related to the exponent calculation function (\toolbox\matlab\elfun\exp.m).

1.4. EXPRESSIONS INMATLAB

An expression is a language construct that includes elements of the language (constants, variables, functions) connected to each other using connecting characters that specify the operations performed when calculating the value of the expression. There are numerical (Nexpression), symbolic (Cexpression) and logical (Lexpression) expressions depending on the result obtained after performing the operations included in the expression.

Top Related Articles