352 Introduction to C++ Programming and Graphics
- while loop:
>> i=0;
>> while i<2, i=i+1; disp(i), end
1
2
The four statements in the while loop could be typed in separate lines; that is,
the commas can be replaced by theEnterkeystroke.
F.5 Matlabfunctions
Matlabcomes with an extensive library of internal functions for numerical
computation and data visualization.
Table F.5.1 lists general and specialized mathematical functions. To ob-
tain specific information on the proper usage of a function, use theMatlabhelp
facility. If you are unsure about the proper syntax or reliability of a function,
it is best to write your own code from first principles. It is both rewarding
and instructive to duplicate aMatlabfunction and create a personal library
of user-defined functions based on control-flow commands.
F.6 User-defined functions
InMatlab, a user-defined function is written in a file whose name defines
the calling name of the function. The file name must be suffixed with the
Matlabidentifier: .m. Thus, a function namedpindosmust reside in a file
namedpindos.m, whose general structure is:
function [output1, output2, ...] = pindos (input1, input2,...)
......
return
The three dots indicate additional input and output arguments sepa-
rated by commas; the six dots indicate additional lines of code. The output
string,output1, output2, ..., consists of numbers, vectors, matrices, and
string variables evaluated by the function by performing operations involving
the input string,input, input2, .... To execute this function in theMat-
labenvironment or invoke it from a program file, we issue the command:
[evaluate1, evaluate2, ...] = pindos (parameter1, parameter2,...)
After the function has been successfully executed,evaluate1takes the value
ofoutput1,evaluate2takes the value ofoutput2, and the rest of the output
variables take corresponding values.