Friday, July 31, 2009

dsearch

Search for nearest point

Syntax

  • K = dsearch(x,y,TRI,xi,yi)
    K = dsearch(x,y,TRI,xi,yi,S)

Description

K = dsearch(x,y,TRI,xi,yi) returns the index into x and y of the nearest point to the point (xi,yi). dsearch requires a triangulation TRI of the points x,y obtained using delaunay. If xi and yi are vectors, K is a vector of the same size.

K = dsearch(x,y,TRI,xi,yi,S) uses the sparse matrix S instead of computing it each time:

  • S = sparse(TRI(:,[1 1 2 2 3 3]),TRI(:,[2 3 1 3 1 2]),1,nxy,nxy)

where nxy = prod(size(x)).




dsearchn

n-D nearest point search

Syntax

  • k = dsearchn(X,T,XI)
    k = dsearchn(X,T,XI,outval)
    k = dsearchn(X,XI)
    [k,d] = dsearchn(X,...)

Description

k = dsearchn(X,T,XI) returns the indices k of the closest points in X for each point in XI. X is an m-by-n matrix representing m points in n-D space. XI is a p-by-n matrix, representing p points in n-D space. T is a numt-by-n+1 matrix, a tessellation of the data X generated by delaunayn. The output k is a column vector of length p.

k = dsearchn(X,T,XI,outval) returns the indices k of the closest points in X for each point in XI, unless a point is outside the convex hull. If XI(J,:) is outside the convex hull, then K(J) is assigned outval, a scalar double. Inf is often used for outval. If outval is [], then k is the same as in the case k = dsearchn(X,T,XI).

k = dsearchn(X,XI) performs the search without using a tessellation. With large X and small XI, this approach is faster and uses much less memory.

[k,d] = dsearchn(X,...) also returns the distances d to the closest points. d is a column vector of length p.

drawnow

Complete pending drawing events

Syntax

  • drawnow

Description

drawnow flushes the event queue and updates the figure window.

Remarks

Other events that cause MATLAB to flush the event queue and draw the figure windows include:

  • Returning to the MATLAB prompt
  • A pause statement
  • A waitforbuttonpress statement
  • A waitfor statement
  • A getframe statement
  • A figure statement

Examples

Executing the statements,

  • x = -pi:pi/20:pi;
    plot(x,cos(x))
    drawnow
    title('A Short Title')
    grid on

as an M-file updates the current figure after executing the drawnow function and after executing the final statement.

dragrect

Drag rectangles with mouse

Syntax

  • [finalrect] = dragrect(initialrect)
    [finalrect] = dragrect(initialrect,stepsize)

Description

[finalrect] = dragrect(initialrect) tracks one or more rectangles anywhere on the screen. The n-by-4 matrix, initialrect, defines the rectangles. Each row of initialrect must contain the initial rectangle position as [left bottom width height] values. dragrect returns the final position of the rectangles in finalrect.

[finalrect] = dragrect(initialrect,stepsize) moves the rectangles in increments of stepsize. The lower-left corner of the first rectangle is constrained to a grid of size equal to stepsize starting at the lower-left corner of the figure, and all other rectangles maintain their original offset from the first rectangle.

[finalrect] = dragrect(...) returns the final positions of the rectangles when the mouse button is released. The default stepsize is 1.

Remarks

dragrect returns immediately if a mouse button is not currently pressed. Use dragrect in a ButtonDownFcn, or from the command line in conjunction with waitforbuttonpress to ensure that the mouse button is down when dragrect is called. dragrect returns when you release the mouse button.

If the drag ends over a figure window, the positions of the rectangles are returned in that figure's coordinate system. If the drag ends over a part of the screen not contained within a figure window, the rectangles are returned in the coordinate system of the figure over which the drag began

Example

Drag a rectangle that is 50 pixels wide and 100 pixels in height.

  • waitforbuttonpress
    point1 = get(gcf,'CurrentPoint') % button down detected
    rect = [point1(1,1) point1(1,2) 50 100]
    [r2] = dragrect(rect)

double

onvert to double-precision

Syntax

  • double(X)

Description

double(x) returns the double-precision value for X. If X is already a double-precision array, double has no effect.

Remarks

double is called for the expressions in for, if, and while loops if the expression isn't already double-precision. double should be overloaded for any object when it makes sense to convert it to a double-precision value.

dot

Vector dot product

Syntax

  • C = dot(A,B)
    C = dot(A,B,dim)

Description

C = dot(A,B) returns the scalar product of the vectors A and B. A and B must be vectors of the same length. When A and B are both column vectors, dot(A,B) is the same as A'*B.

For multidimensional arrays A and B, dot returns the scalar product along the first non-singleton dimension of A and B. A and B must have the same size.

C = dot(A,B,dim) returns the scalar product of A and B in the dimension dim.

Examples

The dot product of two vectors is calculated as shown:

  • a = [1 2 3]; b = [4 5 6];
    c = dot(a,b)

    c =
    32

dos

Execute a DOS command and return result

Syntax

  • dos command
    status = dos('command')
    [status,result] = dos('command')
    [status,result] = dos('command','-echo')

Description

dos command calls upon the shell to execute the given command for Windows systems.

status = dos('command') returns completion status to the status variable.

[status,result] = dos('command') in addition to completion status, returns the result of the command to the result variable.

[status,result] = dos('command','-echo') forces the output to the Command Window, even though it is also being assigned into a variable.

Both console (DOS) programs and Windows programs may be executed, but the syntax causes different results based on the type of programs. Console programs have stdout and their output is returned to the result variable. They are always run in an iconified DOS or Command Prompt Window except as noted below. Console programs never execute in the background. Also, MATLAB will always wait for the stdout pipe to close before continuing execution. Windows programs may be executed in the background as they have no stdout.

The ampersand, &, character has special meaning. For console programs this causes the console to open. Omitting this character will cause console programs to run iconically. For Windows programs, appending this character will cause the application to run in the background. MATLAB will continue processing.

Examples

The following example performs a directory listing, returning a zero (success) in s and the string containing the listing in w.

  • [s, w] = dos('dir');

To open the DOS 5.0 editor in a DOS window

  • dos('edit &')

To open the notepad editor and return control immediately to MATLAB

  • dos('notepad file.m &')

The next example returns a one in s and an error message in w because foo is not a valid shell command.

  • [s, w] = dos('foo')

This example echoes the results of the dir command to the Command Window as it executes as well as assigning the results to w.

  • [s, w] = dos('dir', '-echo');

doc

Display online documentation in MATLAB Help browser

Graphical Interface

As an alternative to the doc function, use the Help browser Search tab. Set the Search type to Function Name, type the function name, and click Go.

Syntax

  • doc
    doc function
    doc toolbox/
    doc toolbox/function

Description

doc opens the Help browser, if it is not already running.

doc function displays the reference page for the MATLAB function function in the Help browser. If function is overloaded, doc displays the reference page for the first function on the search path and lists the overloaded functions in the MATLAB Command Window. If a reference page for the function does not exist, doc displays M-file help in the Help browser.

doc toolbox/ displays the Roadmap page, a summary of the most pertinent documentation for toolbox, in the Help browser.

doc toolbox/function displays the reference page for function that belongs to the specified toolbox, in the Help browser.



docopt

Display location of help file directory for UNIX platforms

Syntax

  • docopt
    [doccmd,options,docpath] = docopt

Description

docopt displays the location of the online help files directory (online documentation location) for UNIX platforms if the web function is used with the -browser option. It is also used for UNIX platforms that do not support Java GUIs--see the "Release 13 Release Notes for more information about these platforms. You specify where the online help directory will be located when you install MATLAB. It can be on a disk or CD-ROM drive in your local system. If you relocate your online help file directory, edit the docopt.m file, changing the location in it. (For Windows and the UNIX platforms that support Java GUIs, select File -> Preferences -> Help to view or change the documentation location.)

[doccmd,options,docpath] = docopt displays three strings: doccmd, options, and docpath.


doccmd
The function that doc uses to display MATLAB documentation. The default is netscape.
options
Additional configuration options for use with doccmd.
docpath
The path to the MATLAB online help files. If docpath is empty, the doc function assumes the help files are in the default location.

Remarks

To globally replace the online help file directory location, update $matlabroot/toolbox/local/docopt.m.

To override the global setting, copy $matlabroot/toolbox/local/docopt.m to $HOME/matlab/docopt.m and make changes there. For the changes to take effect in the current MATLAB session, $HOME/matlab must be on your MATLAB path.



docroot

Get or set root directory for MATLAB help files

Graphical Interface

As an alternative to the docroot function, select File -> Preferences -> Help and set the Documentation location.

Syntax

  • docroot
    docroot('newdocroot')
    docroot(newdocroot, 'cdrom')

Description

docroot displays the current value for docroot, the root directory for MATLAB help files. This is the directory where the MATLAB Help browser looks for the online documentation to display.

docroot('newdocroot') sets the root directory for MATLAB help files to newdocroot, where newdocroot is the full pathname to the help directory. For example, type docroot('d:/matlabr13/help'). One useful application is setting docroot in your startup.m file.

docroot('newdocroot', 'cdrom') sets the root directory for MATLAB help files on the MATLAB documentation CD to newdocroot, where newdocroot is the full pathname to the help directory on your MATLAB documentation CD. For example, type docroot('z:/help', 'cdrom').

Examples

You can include a docroot statement in your startup.m file.

dmperm

Dulmage-Mendelsohn decomposition

Syntax

  • p = dmperm(A)
    [p,q,r,s] = dmperm(A)

Description

p = dmperm(A) if A is square and has full rank, returns a row permutation p so that A(p,:) has nonzero diagonal elements. This permutation is also called a perfect matching. If A is not square or not full rank, p is a vector that identifies a matching of maximum size: for each column j of A, either p(j)=0 or A(p(j),j) is nonzero.

[p,q,r,s] = dmperm(A), where A need not be square or full rank, finds permutations p and q and index vectors r and s so that A(p,q) is block upper triangular. The kth block has indices (r(k):r(k+1)-1, s(k):s(k+1)-1). When A is square and has full rank, r = s.

If A is not square or not full rank, the first block may have more columns and the last block may have more rows. All other blocks are square and irreducible. dmperm permutes nonzeros to the diagonals of square blocks, but does not do this for non-square blocks.

Remarks

If A is a reducible matrix, the linear system can be solved by permuting A to a block upper triangular form, with irreducible diagonal blocks, and then performing block backsubstitution. Only the diagonal blocks of the permuted matrix need to be factored, saving fill and arithmetic in the blocks above the diagonal.

In graph theoretic terms, dmperm finds a maximum-size matching in the bipartite graph of A, and the diagonal blocks of A(p,q) correspond to the strong Hall components of that graph. The output of dmperm can also be used to find the connected or strongly connected components of an undirected or directed graph.

dlmread

Read an ASCII delimited file into a matrix

Graphical Interface

As an alternative to dlmread, use the Import Wizard. To activate the Import Wizard, select Import data from the File menu.

Syntax

  • M = dlmread(filename,delimiter)
    M = dlmread(filename,delimiter,R,C)
    M = dlmread(filename,delimiter,range)

Description

M = dlmread(filename,delimiter) reads numeric data from the ASCII delimited file filename, using the specified delimiter. A comma (,) is the default delimiter. Use '\t' to specify a tab delimiter.

M = dlmread(filename,delimiter,R,C) reads numeric data from the ASCII delimited file filename, using the specified delimiter. The values R and C specify the row and column where the upper-left corner of the data lies in the file. R and C are zero based so that R=0, C=0 specifies the first value in the file, which is the upper left corner.

M = dlmread(filename,delimiter,range) reads the range specified by
range = [R1 C1 R2 C2] where (R1,C1) is the upper-left corner of the data to be read and (R2,C2) is the lower-right corner. range can also be specified using spreadsheet notation as in range = 'A1..B7'.

Remarks

dlmread fills empty delimited fields with zero. Data files having lines that end with a non-space delimiter, such as a semi-colon, produce a result that has an additional last column of zeros.



dlmwrite

Write a matrix to an ASCII delimited file

Syntax

  • dlmwrite(filename,M,delimiter)
    dlmwrite(filename,M,delimiter,R,C)

Description

dlmwrite(filename,M,delimiter) writes matrix M into an ASCII-format file, using delimiter to separate matrix elements. The data is written to the upper left-most cell of the spreadsheet filename. A comma (,) is the default delimiter. Use '\t' to produce tab-delimited files.

dlmwrite(filename,M,delimiter,R,C) writes matrix A into an ASCII-format file, using delimiter to separate matrix elements. The data is written to the spreadsheet filename, starting at spreadsheet cell R and C, where R is the row offset and C is the column offset. R and C are zero based so that R=0, C=0 specifies the first value in the file, which is the upper left corner.

Remarks

The resulting file is readable by spreadsheet programs.

divergence

Computes the divergence of a vector field

Syntax

  • div = divergence(X,Y,Z,U,V,W)
    div = divergence(U,V,W)
    div = divergence(X,Y,U,V)
    div = divergence(U,V)

Description

div = divergence(X,Y,Z,U,V,W) computes the divergence of a 3-D vector field U, V, W. The arrays X, Y, Z define the coordinates for U, V, W and must be monotonic and 3-D plaid (as if produced by meshgrid).

div = divergence(U,V,W) assumes X, Y, and Z are determined by the expression:

  • [X Y Z] = meshgrid(1:n,1:m,1:p)

where [m,n,p] = size(U).

div = divergence(X,Y,U,V) computes the divergence of a 2-D vector field U, V. The arrays X, Y define the coordinates for U, V and must be monotonic and 2-D plaid (as if produced by meshgrid).

div = divergence(U,V) assumes X and Y are determined by the expression:

  • [X Y] = meshgrid(1:n,1:m)

where [m,n] = size(U).

Examples

This example displays the divergence of vector volume data as slice planes using color to indicate divergence.

  • load wind
    div = divergence(x,y,z,u,v,w);
    slice(x,y,z,div,[90 134],[59],[0]);
    shading interp
    daspect([1 1 1])
    camlight




disp (serial)

Display serial port object summary information

Syntax

  • obj
    disp(obj)

Arguments


obj
A serial port object or an array of serial port objects.

Description

obj or disp(obj) displays summary information for obj.

Remarks

In addition to the syntax shown above, you can display summary information for obj by excluding the semicolon when:

  • Creating a serial port object
  • Configuring property values using the dot notation

Use the display summary to quickly view the communication settings, communication state information, and information associated with read and write operations.

Example

The following commands display summary information for the serial port object s.

  • s = serial('COM1')
    s.BaudRate = 300
    s


disp (timer)

Display information about timer object

Syntax

  • obj
    disp(obj)

Description

obj or disp(obj) displays summary information for timer object, obj.

If obj is an array of timer objects, disp outputs a table of summary information about the timer objects in the array.

In addition to the syntax shown above, you can display summary information for obj by excluding the semicolon when:

  • Creating a timer object, using the timer function
  • Configuring property values using the dot notation

Example

The following commands display summary information for the timer object t.

  • t = timer

    Timer Object: timer-1

    Timer Settings
    ExecutionMode: singleShot
    Period: 1
    BusyMode: drop
    Running: off

    Callbacks
    TimerFcn: []
    ErrorFcn: []
    StartFcn: []
    StopFcn: []

This example shows the summary information displayed for an array of timer objects, t_arr.

  • disp(t_arr)

    Timer Object Array

    Index: ExecutionMode: Period: TimerFcn: Name:
    1 singleShot 1 [] timer-1
    2 singleShot 1 [] timer-2



display

Overloaded method to display an object

Syntax

  • display(X)

Description

display(X) prints the value of a variable or expression, X. MATLAB calls display(X) when it interprets a variable or expression, X, that is not terminated by a semicolon. For example, sin(A) calls display, while sin(A); does not.

If X is an instance of a MATLAB class, then MATLAB calls the display method of that class, if such a method exists. If the class has no display method or if X is not an instance of a MATLAB class, then the MATLAB builtin display function is called.

Examples

A typical implementation of display calls disp to do most of the work and looks like this.

  • function display(X)
    if isequal(get(0,'FormatSpacing'),'compact')
    disp([inputname(1) ' =']);
    disp(X)
    else
    disp(' ')
    disp([inputname(1) ' =']);
    disp(' ');
    disp(X)
    end

The expression magic(3), with no terminating semicolon, calls this function as display(magic(3)).

  • magic(3)

    ans =

    8 1 6
    3 5 7
    4 9 2

As an example of a class display method, the function below implements the display method for objects of the MATLAB class, polynom.

  • function display(p)
    % POLYNOM/DISPLAY Command window display of a polynom
    disp(' ');
    disp([inputname(1),' = '])
    disp(' ');
    disp([' ' char(p)])
    disp(' ');

The statement

  • p = polynom([1 0 -2 -5])

creates a polynom object. Since the statement is not terminated with a semicolon, the MATLAB interpreter calls display(p), resulting in the output

  • p =

    x^3 - 2*x - 5

disp

Display text or array

Syntax

  • disp(X)

Description

disp(X) displays an array, without printing the array name. If X contains a text string, the string is displayed.

Another way to display an array on the screen is to type its name, but this prints a leading "X =," which is not always desirable.

Note that disp does not display empty arrays.

Examples

One use of disp in an M-file is to display a matrix with column labels:

  • disp('         Corn         Oats         Hay')
    disp(rand(5,3))

which results in

  •          Corn         Oats         Hay
    0.2113 0.8474 0.2749
    0.0820 0.4524 0.8807
    0.7599 0.8075 0.6538
    0.0087 0.4832 0.4899
    0.8096 0.6135 0.7741

dir

Display directory listing

Syntax

  • dir
    dir name
    files = dir('name')

Description

dir lists the files in the current working directory.

dir name lists the specified files. The name argument can be a pathname, filename, or can include both. You can use absolute and relative pathnames and wildcards (*).

files = dir('directory') returns the list of files in the specified directory (or the current directory, if dirname is not specified) to an m-by-1 structure with the fields


name
Filename
date
Modification date
bytes
Number of bytes allocated to the file
isdir
1 if name is a directory; 0 if not

Examples

List Directory Contents

To view the contents of the matlab/audio directory, type

  • dir $matlabroot/toolbox/matlab/audio

Using Wildcard and File Extension

To view the MAT files in your current working directory that include the term java, type

  • dir *java*.mat

MATLAB returns

  • java_array.mat  javafrmobj.mat  testjava.mat

Using Relative Pathname

To view the M-files in the MATLAB audio directory, type

  • dir(fullfile(matlabroot,'toolbox/matlab/audio/*.m'))

MATLAB returns

  • Contents.m          auread.m            soundsc.m
    audiodevinfo.m auwrite.m wavplay.m
    audioplayer.m lin2mu.m wavread.m
    audioplayerreg.m mu2lin.m wavrecord.m
    audiorecorder.m prefspanel.m wavwrite.m
    audiouniquename.m sound.m

Returning File List to Structure

To return the list of files to the variable audio_files, type

  • audio_files=dir(fullfile(matlabroot,'toolbox/matlab/audio/*.m')
    )

MATLAB returns the information in a structure array.

  • audio_files =
    19x1 struct array with fields:
    name
    date
    bytes
    isdir

Index into the structure to access a particular item. For example,

  • audio_files(3).name
    ans =
    audioplayer.m

diff

Differences and approximate derivatives

Syntax

  • Y = diff(X)
    Y = diff(X,n)
    Y = diff(X,n,dim)

Description

Y = diff(X) calculates differences between adjacent elements of X.

If X is a vector, then diff(X) returns a vector, one element shorter than X, of differences between adjacent elements:

  • [X(2)-X(1) X(3)-X(2) ... X(n)-X(n-1)]

If X is a matrix, then diff(X) returns a matrix of row differences:

  • [X(2:m,:)-X(1:m-1,:)]

In general, diff(X) returns the differences calculated along the first non-singleton (size(X,dim) > 1) dimension of X.

Y = diff(X,n) applies diff recursively n times, resulting in the nth difference. Thus, diff(X,2) is the same as diff(diff(X)).

Y = diff(X,n,dim) is the nth difference function calculated along the dimension specified by scalar dim. If order n equals or exceeds the length of dimension dim, diff returns an empty array.

Remarks

Since each iteration of diff reduces the length of X along dimension dim, it is possible to specify an order n sufficiently high to reduce dim to a singleton (size(X,dim) = 1) dimension. When this happens, diff continues calculating along the next nonsingleton dimension.

Examples

The quantity diff(y)./diff(x) is an approximate derivative.

  • x = [1 2 3 4 5];
    y = diff(x)
    y =
    1 1 1 1

    z = diff(x,2)
    z =
    0 0 0

Given,

  • A = rand(1,3,2,4);

diff(A) is the first-order difference along dimension 2.

diff(A,3,4) is the third-order difference along dimension 4.

diary

Save session to a file

Syntax

  • diary
    diary('filename')
    diary off
    diary on
    diary filename

Description

The diary function creates a log of keyboard input and the resulting output (except it does not include graphics). The output of diary is an ASCII file, suitable for printing or for inclusion in reports and other documents. If you do not specify filename, MATLAB creates a file named diary in the current directory.

diary toggles diary mode on and off. To see the status of diary, type get(0,'Diary'). MATLAB returns either on or off indicating the diary status.

diary('filename') writes a copy of all subsequent keyboard input and the resulting output (except it does not include graphics) to the named file, where filename is the full pathname or filename is in the current MATLAB directory. If the file already exists, output is appended to the end of the file. You cannot use a filename called off or on. To see the name of the diary file, use get(0,'DiaryFile').

diary off suspends the diary.

diary on resumes diary mode using the current filename, or the default filename diary if none has yet been specified.

diary filename is the unquoted form of the syntax.

dialog

Create and display dialog box

Syntax

  • h = dialog('PropertyName',PropertyValue,...)

Description

h = dialog('PropertyName',PropertyValue,...) returns a handle to a dialog box. This function creates a figure graphics object and sets the figure properties recommended for dialog boxes. You can specify any valid figure property value.

diag

Diagonal matrices and diagonals of a matrix

Syntax

  • X = diag(v,k)
    X = diag(v)
    v = diag(X,k)
    v = diag(X)

Description

X = diag(v,k) when v is a vector of n components, returns a square matrix X of order n+abs(k), with the elements of v on the kth diagonal. k = 0 represents the main diagonal, k > 0 above the main diagonal, and k <> below the main diagonal.

X = diag(v) puts v on the main diagonal, same as above with k = 0.

v = diag(X,k) for matrix X, returns a column vector v formed from the elements of the kth diagonal of X.

v = diag(X) returns the main diagonal of X, same as above with k = 0.

Examples

diag(diag(X)) is a diagonal matrix.

sum(diag(X)) is the trace of X.

The statement

  • diag(-m:m)+diag(ones(2*m,1),1)+diag(ones(2*m,1),-1)

produces a tridiagonal matrix of order 2*m+1.

deval

Evaluate the solution of a differential equation problem

Syntax

  • sxint = deval(sol,xint)
    sxint = deval(xint,sol)
    sxint = deval(sol,xint,idx)
    sxint = deval(xint,sol,idx)

Description

sxint = deval(sol,xint) and sxint = deval(xint,sol) evaluate the solution of a differential equation problem. sol is a structure returned by one of these solvers:

  • An initial value problem solver (ode45, ode23, ode113, ode15s, ode23s, ode23t, ode23tb),
  • The delay differential equations solver (dde23),
  • The boundary value problem solver (bvp4c).

xint is a point or a vector of points at which you want the solution. The elements of xint must be in the interval [sol.x(1),sol.x(end)]. For each i, sxint(:,i) is the solution at xint(i).

sxint = deval(sol,xint,idx) and sxint = deval(xint,sol,idx) evaluate as above but return only the solution components with indices listed in idx.

Example

This example solves the system using ode45, and evaluates and plots the first component of the solution at 100 points in the interval [0,20].

  • sol = ode45(@vdp1,[0 20],[2 0]);
    x = linspace(0,20,100);
    y = deval(sol,x,1);
    plot(x,y);




detrend

Remove linear trends.

Syntax

  • y = detrend(x)
    y = detrend(x,'constant')
    y = detrend(x,'linear',bp)

Description

detrend removes the mean value or linear trend from a vector or matrix, usually for FFT processing.

y = detrend(x) removes the best straight-line fit from vector x and returns it in y. If x is a matrix, detrend removes the trend from each column.

y = detrend(x,'constant') removes the mean value from vector x or, if x is a matrix, from each column of the matrix.

y = detrend(x,'linear',bp) removes a continuous, piecewise linear trend from vector x or, if x is a matrix, from each column of the matrix. Vector bp contains the indices of the breakpoints between adjacent linear segments. The breakpoint between two segments is defined as the data point that the two segments share.

detrend(x,'linear'), with no breakpoint vector specified, is the same as detrend(x).

Example

  • sig = [0 1 -2 1 0 1 -2 1 0];      % signal with no linear trend
    trend = [0 1 2 3 4 3 2 1 0]; % two-segment linear trend
    x = sig+trend; % signal with added trend
    y = detrend(x,'linear',5) % breakpoint at 5th element

    y =

    -0.0000
    1.0000
    -2.0000
    1.0000
    0.0000
    1.0000
    -2.0000
    1.0000
    -0.0000

Note that the breakpoint is specified to be the fifth element, which is the data point shared by the two segments.

Algorithm

detrend computes the least-squares fit of a straight line (or composite line for piecewise linear trends) to the data and subtracts the resulting function from the data. To obtain the equation of the straight-line fit, use polyfit.

det

Matrix determinant

Syntax

  • d = det(X)

Description

d = det(X) returns the determinant of the square matrix X. If X contains only integer entries, the result d is also an integer.

Remarks

Using det(X) == 0 as a test for matrix singularity is appropriate only for matrices of modest order with small integer entries. Testing singularity using abs(det(X)) <= tolerance is not recommended as it is difficult to choose the correct tolerance. The function cond(X) can check for singular and nearly singular matrices.

Algorithm

The determinant is computed from the triangular factors obtained by Gaussian elimination

  • [L,U] = lu(A)
    s = det(L) % This is always +1 or -1
    det(A) = s*prod(diag(U))

Examples

The statement A = [1 2 3; 4 5 6; 7 8 9]

produces

  • A =
    1 2 3
    4 5 6
    7 8 9

This happens to be a singular matrix, so d = det(A) produces d = 0. Changing A(3,3) with A(3,3) = 0 turns A into a nonsingular matrix. Now d = det(A) produces d = 27.

depfun

List the dependent functions of an M-file or P-file

Syntax

  • list = depfun('file_name');
    [list,builtins,classes] = depfun('file_name');
    [list,builtins,classes,prob_files,prob_sym,eval_strings,...
    called_from,java_classes] = depfun('file_name');
    [...] = depfun('file_name1','file_name2',...);
    [...] = depfun('fig_file_name');
    [...] = depfun(...,'-toponly');

Description

The depfun function lists all of the functions and scripts, as well as built-in functions, that a specified M-file needs to operate. This is useful for finding all of the M-files that you need to compile for a MATLAB runtime application.

list = depfun('file_name') creates a cell array of strings containing the paths of all the files that file_name.m uses. This includes the second-level files that are called directly by file_name.m, as well as the third-level files that are called by the second-level files, and so on.

    Note If depfun reports that "These files could not be parsed:" or if the prob_files output below is nonempty, then the rest of the output of depfun might be incomplete. You should correct the problematic files and invoke depfun again.

[list,builtins,classes] = depfun('file_name') creates three cell arrays containing information about dependent functions. list contains the paths of all the files that file_name and its subordinates use. builtins contains the built-in functions that file_name and its subordinates use. classes contains the MATLAB classes that file_name and its subordinates use.

[list,builtins,classes,prob_files,prob_sym,eval_strings,...
called_from,java_classes] = depfun('file_name')
creates additional cell arrays or structure arrays containing information about any problems with the depfun search and about where the functions in list are invoked. The additional outputs are:

  • prob_files, which indicates which files depfun was unable to parse, find, or access. Parsing problems can arise from MATLAB syntax errors. prob_files is a structure array whose fields are:
    • name, which gives the names of the files
    • listindex, which tells where the files appeared in list
    • errmsg, which describes the problems
  • prob_sym, which indicates which symbols depfun was unable to resolve as functions or variables. It is a structure array whose fields are:
    • fcn_id, which tells where the files appeared in list
    • name, which gives the names of the problematic symbols
  • eval_strings, which indicates usage of these evaluation functions: eval, evalc, evalin, feval. When preparing a runtime application, you should examine this output to determine whether an evaluation function invokes a function that does not appear in list. The output eval_strings is a structure array whose fields are:
    • fcn_name, which give the names of the files that use evaluation functions
    • lineno, which gives the line numbers in the files where the evaluation functions appear
  • called_from, a cell array of the same length as list. This cell array is arranged so that
  • list(called_from{i})

    returns all functions in file_name that invoke the function list{i}.

  • java_classes, a cell array of Java class names that file_name and its subordinates use

[...] = depfun('file_name1','file_name2',...) performs the same operation for multiple files. The dependent functions of all files are listed together in the output arrays.

[...] = depfun('fig_file_name') looks for dependent functions among the callback strings of the GUI elements that are defined in the .fig or .mat file named fig_file_name.

[...] = depfun(...,'-toponly') differs from the other syntaxes of depfun in that it examines only the files listed explicitly as input arguments. It does not examine the files on which they depend. In this syntax, the flag '-toponly' must be the last input argument.

Notes

  1. If depfun does not find a file called hginfo.mat on the path, then it creates one. This file contains information about Handle Graphics callbacks.
  2. If your application uses toolbar items from the MATLAB default figure window, then you must include 'FigureToolBar.fig' in your input to depfun.
  3. If your application uses menu items from the MATLAB default figure window, then you must include 'FigureMenuBar.fig' in your input to depfun.
  4. Because many built-in Handle Graphics functions invoke newplot, the list produced by depfun always includes the functions on which newplot is dependent:
    • 'matlabroot\toolbox\matlab\graphics\newplot.m'
    • 'matlabroot\toolbox\matlab\graphics\closereq.m'
    • 'matlabroot\toolbox\matlab\graphics\gcf.m'
    • 'matlabroot\toolbox\matlab\graphics\gca.m'
    • 'matlabroot\toolbox\matlab\graphics\private\clo.m'
    • 'matlabroot\toolbox\matlab\general\@char\delete.m'
    • 'matlabroot\toolbox\matlab\lang\nargchk.m'
    • 'matlabroot\toolbox\matlab\uitools\allchild.m'
    • 'matlabroot\toolbox\matlab\ops\setdiff.m'
    • 'matlabroot\toolbox\matlab\ops\@cell\setdiff.m'
    • 'matlabroot\toolbox\matlab\iofun\filesep.m'
    • 'matlabroot\toolbox\matlab\ops\unique.m'
    • 'matlabroot\toolbox\matlab\elmat\repmat.m'
    • 'matlabroot\toolbox\matlab\datafun\sortrows.m'
    • 'matlabroot\toolbox\matlab\strfun\deblank.m'
    • 'matlabroot\toolbox\matlab\ops\@cell\unique.m'
    • 'matlabroot\toolbox\matlab\strfun\@cell\deblank.m'
    • 'matlabroot\toolbox\matlab\datafun\@cell\sort.m'
    • 'matlabroot\toolbox\matlab\strfun\cellstr.m'
    • 'matlabroot\toolbox\matlab\datatypes\iscell.m'
    • 'matlabroot\toolbox\matlab\strfun\iscellstr.m'
    • 'matlabroot\toolbox\matlab\datatypes\cellfun.dll'

Examples

  • list = depfun('mesh'); % Files mesh.m depends on
    list = depfun('mesh','-toponly') % Files mesh.m depends on
    directly
    [list,builtins,classes] = depfun('gca');

depdir

List the dependent directories of an M-file or P-file

Syntax

  • list = depdir('file_name');
    [list,prob_files,prob_sym,prob_strings] = depdir('file_name');
    [...] = depdir('file_name1','file_name2',...);

Description

The depdir function lists the directories of all of the functions that a specified M-file or P-file needs to operate. This function is useful for finding all of the directories that need to be included with a runtime application and for determining the runtime path.

list = depdir('file_name') creates a cell array of strings containing the directories of all the M-files and P-files that file_name.m or file_name.p uses. This includes the second-level files that are called directly by file_name, as well as the third-level files that are called by the second-level files, and so on.

[list,prob_files,prob_sym,prob_strings] = depdir('file_name') creates three additional cell arrays containing information about any problems with the depdir search. prob_files contains filenames that depdir was unable to parse. prob_sym contains symbols that depdir was unable to find. prob_strings contains callback strings that depdir was unable to parse.

[...] = depdir('file_name1','file_name2',...) performs the same operation for multiple files. The dependent directories of all files are listed together in the output cell arrays.

Example

  • list = depdir('mesh')

demo

demos via Help browser

Syntax

  • demo
    demo subtopic
    demo subtopic category

Description

demo opens the Demos panel in the Help browser. In the left pane, expand the listing for a product area (for example, MATLAB). Within that product area, expand the listing for a product or product category (for example, MATLAB Graphics). Select a specific demo from the list (for example, Visualizing Sound). In the right pane, view instructions for using the demo.

For platforms that do not support Java GUIs, the demos are presented in a non-Java interface. To run a demo from the command line, type the demo name. For playshow demos, that is those demos in which the H1 line begins with two comment symbols (%%), type playshow followed by the demo name.

demo subtopic opens the Demos panel in the Help browser with the specified subtopic expanded. Subtopics are matlab, toolbox, simulink, and blockset.

demo subtopic product opens the Demos panel in the Help browser to the specified product or category within the subtopic.

Examples

Accessing Toolbox Demos

To find the demos relating to the Communications Toolbox, type

  • demo toolbox communication

The Help browser opens to the Demos panel with the Toolbox subtopic expanded and with the Communications product highlighted and expanded to show the available demos.

Accessing the Simulink Automotive Demos

To accesses the automotive demos within Simulink, type

  • demo simulink automotive

The Demos panel opens with the Simulink subtopic and Automotive category expanded.

Running a Demo from the Command Line

Type

  • vibes

to run a visualization demonstration showing an animated L-shaped membrane.

Running a Playshow Demo from the Command Line

Type

  • quake

to run an earthquake data demo. Not much appears to happen. This is because quake is a playshow demo. Verify this by viewing the M-file, quake.m, for example, by typing

  • edit quake

The first line, that is, the H1 line for quake is

  • %% Loma Prieta Earthquake

The %% indicates that quake is a playshow demo. So to run it, type

  • playshow quake
and the earthquake demo runs.

delete

Delete files or graphics objects

Syntax

  • delete filename
    delete(h)
    delete('filename')

Description

delete filename deletes the named file from the disk. The filename may include an absolute pathname or a pathname relative to the current directory. The filename may also include wildcards, (*).

delete(h) deletes the graphics object with handle h. The function deletes the object without requesting verification even if the object is a window.

delete('filename') is the function form of delete. Use this form when the filename is stored in a string.

    Note MATLAB does not ask for confirmation when you enter the delete command. To avoid accidentally losing files or graphics objects that you need, make sure that you have accurately specified the items you want deleted.

Examples

To delete all files with a .mat extension in the ../mytests/ directory, type

  • delete('../mytests/*.mat')

To delete a directory, use rmdir rather than delete:

  • rmdir mydirectory


delete (COM)

Delete a COM control or server

Syntax

  • delete(h)

Arguments

h
Handle for a COM object previously returned from actxcontrol, actxserver, get, or invoke.

Description

Release all interfaces derived from the specified COM server or control, and then delete the server or control itself. This is different from releasing an interface, which releases and invalidates only that interface.

Examples

Create a Microsoft Calender application. Then create a TitleFont interface and use it to change the appearance of the font of the calendar's title:

  • f = figure('pos',[300 300 500 500]);
    cal = actxcontrol('mscal.calendar', [0 0 500 500], f);

    TFont = get(cal, 'TitleFont')
    TFont =
    Interface.mscal.calendar.TitleFont

    set(TFont, 'Name', 'Viva BoldExtraExtended');
    set(TFont, 'Bold', 0);

When you're finished working with the title font, release the TitleFont interface:

  • release(TFont);

Now create a GridFont interface and use it to modify the size of the calendar's date numerals:

  • GFont = get(cal, 'GridFont')
    GFont =
    Interface.mscal.calendar.GridFont

    set(GFont, 'Size', 16);

When you're done, delete the cal object and the figure window. Deleting the cal object also releases all interfaces to the object (e.g., GFont):

  • delete(cal);
    delete(f);
    clear f;

Note that, although the object and interfaces themselves have been destroyed, the variables assigned to them still reside in the MATLAB workspace until you remove them with clear.

  • whos
    Name Size Bytes Class

    GFont 1x1 0 handle
    TFone 1x1 0 handle
    cal 1x1 0 handle

    Grand total is 3 elements using 0 bytes


delete (serial)

Remove a serial port object from memory

Syntax

  • delete(obj)

Arguments


obj
A serial port object or an array of serial port objects.

Description

delete(obj) removes obj from memory.

Remarks

When you delete obj, it becomes an invalid object. Because you cannot connect an invalid serial port object to the device, you should remove it from the workspace with the clear command. If multiple references to obj exist in the workspace, then deleting one reference invalidates the remaining references.

If obj is connected to the device, it has a Status property value of open. If you issue delete while obj is connected, then the connection is automatically broken. You can also disconnect obj from the device with the fclose function.

If you use the help command to display help for delete, then you need to supply the pathname shown below.

  • help serial/delete

Example

This example creates the serial port object s, connects s to the device, writes and reads text data, disconnects s from the device, removes s from memory using delete, and then removes s from the workspace using clear.

  • s = serial('COM1');
    fopen(s)
    fprintf(s,'*IDN?')
    idn = fscanf(s);
    fclose(s)
    delete(s)
    clear s


delete (timer)

Remove a timer object from memory

Syntax

  • delete(obj)

Description

delete(obj) removes timer object, obj, from memory. If obj is an array of timer objects, delete removes all the objects from memory.

When you delete a timer object, it becomes invalid and cannot be reused. Use the clear command to remove invalid timer objects from the workspace.

If multiple references to a timer object exist in the workspace, deleting the timer object invalidates the remaining references. Use the clear command to remove the remaining references to the object from the workspace.



deleteproperty (COM)

Remove custom property from COM object

Syntax

  • deleteproperty(h, 'propertyname')

Arguments

h
Handle for a COM object previously returned from actxcontrol, actxserver, get, or invoke.

propertyname
A string specifying the name of the custom property to delete.

Description

Delete a property, propertyname, from the custom properties belonging to object or interface, h.

Examples

Create an mwsamp control and add a new property named Position to it. Assign an array value to the property:

  • f = figure('pos', [100 200 200 200]);
    h = actxcontrol('mwsamp.mwsampctrl.2', [0 0 200 200], f);
    get(h)
    Label: 'Label'
    Radius: 20

    addproperty(h, 'Position');
    set(h, 'Position', [200 120]);
    get(h)
    Label: 'Label'
    Radius: 20
    Position: [200 120]

Delete the custom Position property:

  • deleteproperty(h, 'Position');
    get(h)
    Label: 'Label'
    Radius: 20

delaunayn

n-D Delaunay tessellation

Syntax

  • T = delaunayn(X)

Description

T = delaunayn(X) computes a set of simplices such that no data points of X are contained in any circumspheres of the simplices. The set of simplices forms the Delaunay tessellation. X is an m-by-n array representing m points in n-D space. T is a numt-by-(n+1) array where each row contains the indices into X of the vertices of the corresponding simplex.

Visualization

Plotting the output of delaunayn depends of the value of n:

  • You cannot plot delaunayn output for n > 3.

Example

This example generates an n-D Delaunay tessellation, where n = 3.

  • d = [-1 1];
    [x,y,z] = meshgrid(d,d,d); % A cube
    x = [x(:);0];
    y = [y(:);0];
    z = [z(:);0];
    % [x,y,z] are corners of a cube plus the center.
    X = [x(:) y(:) z(:)];
    Tes = delaunayn(X)

    Tes =
    9 1 5 6
    3 9 1 5
    2 9 1 6
    2 3 9 4
    2 3 9 1
    7 9 5 6
    7 3 9 5
    8 7 9 6
    8 2 9 6
    8 2 9 4
    8 3 9 4
    8 7 3 9

You can use tetramesh to visualize the tetrahedrons that form the corresponding simplex. camorbit rotates the camera position to provide a meaningful view of the figure.

  • tetramesh(Tes,X);camorbit(20,0)



Algorithm

delaunayn is based on Qhull [2],. It uses the Qhull joggle option ('QJ'). For information about qhull, see http://www.geom.umn.edu/software/qhull/. For copyright information, see http://www.geom.umn.edu/software/download/COPYING.html.