% for this piecewise example, % f(x) = x when 0 < x < 5 % f(x) = sin(x) for 5 < x < 10 % f(x) = 0 for all other values of x function z = TwoPieces(x) % get the number of columns in x n = size(x,2) for i = 1:n if x(i) > 0 & x(i) <= 5 z(i) = x(i); elseif x(i) > 5 & x(i) < 10 z(i) = sin(x(i)); else z(i) = 0; end end