General purpose functions

The general purpose functions are used for managing variables and workspace, control of output, etc. The functions listed here are a subset of the general purpose functions described in the MATLAB manual. The functions can be divided into the following groups:

General functions

help

Online documentation

type

List file

what

Directory listing of .m-files, .mat-files and .mex-files

Continuation

%

Write a comment line

Variables and workspace

clear

Remove variables from workspace

disp

Display a variable in matrix bank on display screen

load

Retrieve variable from disk and load in workspace

save

Save workspace variables on disk

who, whos

List directory of variables in matrix bank

Files and command window

diary

Save session in a disk file

echo

Control output on the display screen

format

Control the output display format

quit

Terminate CALFEM session

General functions

help

Purpose:

Display a description of purpose and syntax for a specific function.

Syntax:
help function_name
Description:

help provides an online documentation for the specified function.

Example:

Typing

>> help spring1e

yields

Ke=spring1e(ep)
-------------------------------------------------------------
PURPOSE
Compute element stiffness matrix for spring (analog) element.

INPUT:  ep = [k]; spring stiffness or analog quantity.

OUTPUT: Ke : stiffness matrix, dim(Ke)= 2 x 2
-------------------------------------------------------------

Note

This is a MATLAB built-in function. For more information about the help function, type help help.

type

Purpose:

List file.

Syntax:
type filename
Description:

type filename lists the specified file. Use path names in the usual way for your operating system. If a filename extension is not given, .m is added by default. This makes it convenient to list the contents of .m-files on the screen.

Note

This is a MATLAB built-in function. For more information about the type function, type help type.

what

Purpose:

Directory listing of .m-files, .mat-files and mex-files.

Syntax:
what
what dirname
Description:

what lists the .m-files, .mat-files and .mex-files in the current directory.

what dirname lists the files in directory dirname in the MATLAB search path. The syntax of the path depends on your operating system.

Note

This is a MATLAB built-in function. For more information about the what function, type help what.

Purpose:

Continuation.

Syntax:
...
Description:

An expression can be continued on the next line by using ... .

Note

This is a MATLAB built-in function.

%

Purpose:

Write a comment line.

Syntax:
% arbitrary text
Description:

An arbitrary text can be written after the symbol %.

Note

This is a MATLAB built-in character.

Variables and workspace

clear

Purpose:

Remove variables from workspace.

Syntax:
clear
clear name1 name2 name3 ...
Description:

clear removes all variables from workspace.

clear name1 name2 name3 ... removes specified variables from workspace.

Note

This is a MATLAB built-in function. For more information about the clear function, type help clear.

disp

Purpose:

Display a variable in matrix bank on display screen.

Syntax:
disp(A)
Description:

disp(A) displays the matrix A on the display screen.

Note

This is a MATLAB built-in function. For more information about the disp function, type help disp.

load

Purpose:

Retrieve variable from disk and load in workspace.

Syntax:
load filename
load filename.ext
Description:

load filename retrieves the variables from the binary file filename.mat.

load filename.ext reads the ASCII file filename.ext with numeric data arranged in \(m\) rows and \(n\) columns. The result is an \(m \times n\) matrix residing in workspace with the name filename, i.e. with the extension stripped.

Note

This is a MATLAB built-in function. For more information about the load function, type help load.

save

Purpose:

Save workspace variables on disk.

Syntax:
save filename
save filename variables
save filename variables -ascii
Description:

save filename writes all variables residing in workspace in a binary file named filename.mat.

save filename variables writes named variables, separated by blanks, in a binary file named filename.mat.

save filename variables -ascii writes named variables in an ASCII file named filename.

Note

This is a MATLAB built-in function. For more information about the save function, type help save.

who, whos

Purpose:

List directory of variables in matrix bank.

Syntax:
who
whos
Description:

who lists the variables currently in memory.

whos lists the current variables and their size.

Examples:
who

Your variables are:

A       B       C       K       M       X       k       lambda
whos

Name         Size            Bytes  Class     Attributes

A            3x3                72  double
B            3x3                72  double
C            3x3                72  double
K           20x20             3200  double
M           20x20             3200  double
X           20x20             3200  double
k            1x1                 8  double
lambda      20x1               160  double

Note

These are MATLAB built-in functions. For more information about the functions, type help who or help whos.

Files and command window

diary

Purpose:

Save session in a disk file.

Syntax:
diary filename
diary off
diary on
Description:

diary filename writes a copy of all subsequent keyboard input and most of the resulting output (but not graphs) on the named file. If the file filename already exists, the output is appended to the end of that file.

diary off stops storage of the output.

diary on turns it back on again, using the current filename or default filename diary if none has yet been specified.

The diary function may be used to store the current session for later runs. To make this possible, finish each command line with semicolon ‘;’ to avoid the storage of intermediate results on the named diary file.

Note

This is a MATLAB built-in function. For more information about the diary function, type help diary.

echo

Purpose:

Control output on the display screen.

Syntax:
echo on
echo off
echo
Description:

echo on turns on echoing of commands inside Script-files.

echo off turns off echoing.

echo by itself toggles the echo state.

Note

This is a MATLAB built-in function. For more information about the echo function, type help echo.

format

Purpose:

Control the output display format.

Syntax:

See the listing below.

Description:

format controls the output format. By default, MATLAB displays numbers in a short format with five decimal digits.

Command

Result

Example

format short

5 digit scaled fix point

3.1416

format short

16 digit scaled fix point

3.141592653589793

format short e

5 digit floating point

3.1416e+00

format long e

16 digit floating point

3.141592653589793e+00

Note

This is a MATLAB built-in function. For more information about the format function, type help format.

quit

Purpose:

Terminate CALFEM session.

Syntax:
quit
Description:

quit terminates CALFEM without saving the workspace.

Note

This is a MATLAB built-in function. For more information about the quit function, type help quit.