I couldn't find a simple answer to this thing I'm trying to do in Matlab. I have a function file that does some calculation for a given parameter a:
[]=my_function(...,a)
...
Calculations to obtain some functions y_1(x),y_2(x),... for a given parameter a.
...
figure(1);
plot(x,y_1);
title('y_1(x)');
xlabel('x');
ylabel('y_1');
set(legend(sprintf('y_1(x) for a=%g',a)),'interpreter','latex','Location','best');
figure(2);
plot(x,y_2);
title('y_2(x)');
xlabel('x');
ylabel('y_2');
set(legend(sprintf('y_2(x) for a=%g',a)),'interpreter','latex','Location','best');
...
I'm interested in plotting y_1(x) for different values of a (say 5 different values), all in a single figure (with a proper legend of course). Likewise the same for y_2(x),y_3(x), etc....
Whats the simplest way to do it?
I was thinking of making my_function return the plot/figure handle for each of the y_i's and then make a new script/function file that will do something like:
a=[0,1,3,5,7];
h_1=my_function(...,a(1));
h_2=my_function(...,a(2));
...
and somehow combine the figures from h_1 and h_2, but I'm not sure how to do it properly with the legend and everything.