Graphics Programs Reference
In-Depth Information
Functions and programscan becreatedwith the MATLAB editor/debugger and
savedwith the .m extension (MATLAB calls them M-files). The file nameofa saved
function shouldbe identical to the name of the function. For example, if the function
for Gauss elimination listedabove issavedas gauss.m , itcan becalledjust like any
MATLAB function:
>>A=[210;-122;014];
>>b=[1;2;3];
>> soln = gauss(A,b)
soln =
0.2500
0.5000
0.6250
1.2
Data Types and Variables
Data Types
The most commonlyused MATLAB data types, or classes , are double , char and
logical , all of which areconsideredbyMATLAB as arrays. Numericalobjects
belong to the class double , which represents double-precision arrays;ascalar is
treatedas a1
1 array. The elements of a char type array arestrings (sequences
of characters), whereas a logical type array element may contain only1(true) or 0
(false).
Another importantclass is function handle , which is uniquetoMATLAB. It
contains informationrequired to find and execute a function. The nameofa function
handle consists of the character @, followedbythe name of the function; e.g., @sin .
Function handles are usedas input arguments in function calls.For example, suppose
that wehave a MATLAB function plot(func,x1,x2) that plots any user-specified
function func from x1 to x2 . The function call to plot sin x from 0to
×
π
wouldbe
plot(@sin,0,pi) .
There are otherdata types, butwe seldomcome across theminthistext. Additional
classes can be definedbythe user. The class of an object can be displayedwith the
class command. For example,
>>x=1+3i %Complexnumber
>> class(x)
ans =
double
Search WWH ::




Custom Search