2. Functions

a=magic(4)
a'

Notice that a' gave the transpose of a. Try these

3*a
-a
a+(-a)
b=max(a)
max(b)

Some functions can return more than one value. The function max will return the maximum value and also the column index where the maximum occurs. Try

[m,i]=max(b)
min(a)
b=2*ones(size(a))
a*b
a

Usually a dot in front of an operation will change the operation. In the case of multiplication a.*b will give entry-by-entry multiplication instead of the usual matrix multiplication. Try (dont forget the "dot"):

a.*b
x=5
x^2
a*a
a^2
a.^2
a
triu(a)
diag(a)
diag(diag(a))
c=rand(4,5)
size(c)
[m,n]=size(c)
m
d=.5-c

There are many functions we apply to scales which can also be applied to matrices. Try

sin(d)
exp(d)
log(d)
abs(d)

MATLAB has functions to round floating point numbers to integers. The functions are round, fix, ceil, and floor. Try these

f=[-.5 .1 .5]
round(f)
fix(f)
ceil(f)
floor(f)
sum(f)
prod(f)


Next Section: 3. Relations and Logical Operations


Created by F.G. Garvan (fgarvan@ufl.edu) on Tue, Sep 30, 97
Last update made Mon May 15 13:22:50 EDT 2017.
Back to Table of Contents
EMAIL: fgarvan@ufl.edu fgarvan@ufl.edu