Exercise 6.7: IF loops

Make a function file of the following form:

function B = replace2(A)

in which all elements of a matrix greater than 5 are replaced by 0. Do this without using the command >> find.

(HINT 1: Use the commands >> if and >> for)
(HINT 2: Take the function file from the previous exercise as starting point.)
a)
Work out the problem on paper.
b)
Write the m-file in MATLAB.
c)
Test the function file with the matrix [2 12;5 8] and, if necessary, debug the file.



Previous      Next      Up      Answer


Esteur 2010-03-22