Upgrading from MATLAB 4 to MATLAB 5.0     Search    Help Desk 

Programming Capabilities

MATLAB 5.0 included flow-control improvements and new M-file programming tools.

Flow-Control Improvements

MATLAB 5.0 featured:

The switch statement is a convenient way to execute code conditionally when you have many possible cases to choose from. It is no longer necessary to use a series of elseif statements:

Only the first matching case is executed.

switch can handle multiple conditions in a single case statement by enclosing the case expression in a cell array. For example, assume method exists as a string variable:

Table 1-6: New Flow Control Commands
Command
Description
case
Case switch.
otherwise
Default part of switch statement.
switch
Conditionally execute code, switching among several cases.

MATLAB now evaluates if expressions more efficiently than before. For example, consider the expression if a|b. If a is true, then MATLAB will not evaluate b. Similarly, MATLAB won't execute statements following the expression if a&b in the event a is found to be false.

Table 1-7: New Logical Operators
Operator
Description
iscell
True for a cell array.
isequal
True if arrays are equal.
isfinite
True for finite elements.
islogical
True for logical arrays.
isnumeric
True if input is a numeric array.
isstruct
True for a structure.
logical
Convert numeric values to logical vectors.

M-File Programming Tools

MATLAB 5.0 added four features to enhance MATLAB's M-file programming capabilities.

Variable Number of Input and Output Arguments

The varargin and varargout commands simplify the task of passing data into and out of M-file functions. For instance, the statement function varargout = myfun(A,B) allows M-file myfun to return an arbitrary number of output arguments, while the statement function [C,D] = myfun(varargin) allows it to accept an arbitrary number of input arguments.

Multiple Functions Within an M-File

It is now possible to have subfunctions within the body of an M-file. These are functions that the primary function in the file can access but that are otherwise invisible.

M-File Profiler

This utility lets you debug and optimize M-files by tracking cumulative execution time for each line of code. Whenever the specified M-file executes, the profiler counts how many time intervals each line uses.

Pseudocode M-Files

The pcode command saves a pseudocode version of a function or script to disk for later sessions. This pseudocode version is ready-to-use code that MATLAB can access whenever you invoke the function.

Table 1-8: New Programming Tools  
Function
Description
addpath
Append directory to MATLAB's search path.
assignin
Assign variable in workspace.
edit
Edit an M-file.
editpath
Modify current search path.
evalin
Evaluate variable in workspace.
fullfile
Build full filename from parts.
inmem
Return functions in memory.
inputname
Return input argument name.
mfilename
Return name of the currently running M-file.
mexext
Return the MEX filename extension.
pcode
Create pseudocode file (P-file).
profile
Measure and display M-file execution profiles.
rmpath
Remove directories from MATLAB's search path.
varargin, varargout
Pass or return variable numbers of arguments.
warning
Display warning message.
web
Point Web browser at file or Web site.



[ Previous | Help Desk | Next ]