Graphics Programs Reference
39 Answers to Exercises
(Part I, Basics of MATLAB)
Exercise 1 (Page 9)
The first three columns are a copy of the a matrix. The second three
columns are the elements of a indexed by the elements of a . For example,
a(a(3,2)) = a(8) = 6 , which yields the marked element >6< of the
>> [a a(a)]
Exercise 2 (Page 39)
function out = posneg(in)
% Test for all positive (1), or all negative (-1) elements.
out = -1;
Exercise 3 (Page 44)
The clown's hair is orange. You can use load clown to load the data
(type clear first to get rid of any superfluous data). Typing whos will
tell you that the workspace contains a matrix X and a variable map . Use
image(X),colormap(map) to view the image.
Exercise 4 (Page 49)
We want to fit the data to an exponential curve:
p = Ae Bx .
First we take logs to convert to a linear equation:
log p = log A + Bx.