image - Different plots in the same figure when using clear -


i have 3 .m files , each 1 plots graph. need superimpose results 3 of them, did copy 3 codes single .m file.

the problem need clean (by using command "clear"), between every program, , therefore, between every plot.

anyone has suggestion on how plot 3 results in single figure, please?

thanks! :-)

try following approach: single file containing 4 functions.

function ploteverything()   [x1 y1] = data1();   [x2 y2] = data2();   [x3 y3] = data3(0.5);   figure   plot(x1, y1);   hold all;   plot(x2, y2);   plot(x3, y3);   title 'my awesome plot of everything';   xlabel 'x'; ylabel 'y';   legend({'one', 'two', 'three'}); end  function [x y] = data1()   x = 1:5;   y = 0.5 * x; end  function [x y] = data2()   x = 2:2:10;   y = sqrt(x); end  function [x y] = data3(p)   x = linspace(0,7,15);   y = 0.1 * rand(size(x)) + p * x.^2; end 

put al in file ploteverything.m, , call command line ploteverything. no need explicitly clear variables - created in of functions gone time last function returns, , created individual functions (note called x, y - deliberate) invisible other functions has local scope.

now code organized - there function plotting, , function generating data goes each of plots. functions data1 etc more complicated mine, idea same.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -