MATLAB: How to write a function that returns a graph

matlab function

If I write a function like
function A = myplot(x,y)
A = plot(x,y);
set(Aetc....)
end
When I call this function, a lot of numbers instead of a plot are shown. If modify the code as follows,
function A = myplot(x,y)
plot(x,y)
end
then an error occurs as output argument "A" is not assigned during the call to the function.
How may I correct this?

Best Answer

your 2nd syntex shouldn't give any error, you need to not specify output argument while calling the function from command prompt:
a = myplot(x,y) % will result in error as a isn't defined
myplot(x,y) % will give you desired result
Moreover you also don't need to have any output arguments while defining the function:
function myplot(x,y)
%function body
end