MATLAB: Plot function into subplots

functionhandlesplotsubplot

Hey,
I have a function which creates a plot. Now I want to run this function multiple times and put each plot into a subplot slot.
It should be something like this:
function[] = myplot(x,y)
plot(x,y);
end
subplot(3,1,1) = myplot(input_x1,input_y1);
subplot(3,1,2) = myplot(input_x2,input_y2);
subplot(3,1,3) = myplot(input_x3,input_y3);
This doesn't seem to work, is there an easy way to do this? Maybe with an appropriate output for the function which can be used?
Or maybe with the correct plot handle?
Any help for a simple solution would be nice.
Thanks.

Best Answer

for i=1:3
hAx(i)=subplot(3,1,i);
plot(x(:,i),y(:,i));
end
presuming all x,y are same length. If they're not, then saving them as cell arrrays is an expedient way; just dereference the array with {} inside the loop