[Solved] How to plot two functions on one graph?


every time you call plot matlab will clean the canvas before drawing the new function, unless you are focused on a window where you called hold on, which will substantially tells Matlab to keep the old stuff and superimpose the new drawing.

x = 0:0.001:10

y1 = x.^3;
y2 = 3.^x;

plot(x, y1);
hold on; % without this one will delete y1 before drawing y2
plot(x, y2, 'r');

4

solved How to plot two functions on one graph?