% This illustrates how to use fplot command and text % manipulation to plot functions defined symbolically. % This code plot a piece-wise function defined on the % interval [1,11] where each piece is a linear function % of the form ax+b. % A for loop is used to plot each piece, and "hold on" % command is used to keep the previous plots along with % the new one. The coefficients a,b are chosen randomly % during each iteration. -Caner Kazanci function multi_plot(); figure; hold on; for i=1:10 a = ceil( 5 * rand(1,2) ); fn = [ num2str(a(1)) '*x+' num2str(a(2)) ]; [x,y]= fplot( fn , [i,i+1] ); plot(x,y) end clear all % Octave does not have "fplot" command. The code below % uses only the "plot" command for the same result. figure hold on; for i=1:10 a = ceil( 5 * rand(1,2) ); x = i:.01:(i+1); y = a(1) * x + a(2); plot(x,y) end