Can you create a plot within your function?

47 次查看(过去 30 天)
I was wondering if it is possible to create a function which will create plot of some values. Normally, I would write something like:
function[VR,VC]=RC(V,R,C,t)
VR = (V*(exp(-t/(R*C))));
VC = (V*(1-exp(-t/(R*C))));
But would I be able to expand this function to create a graph of VR against VC, so instead of numerical values I would get a graph? Is this actually possible?

采纳的回答

Matt Fig
Matt Fig 2012-11-4
Sure it is possible! Functions do not have to return anything:
function[]=RC(V,R,C,t)
VR = (V*(exp(-t/(R*C))));
VC = (V*(1-exp(-t/(R*C))));
plot(VR,VC)
Now from the command line:
RC(5,.01,.02,0:.01:5)
Note that you could have the function return those values, and plot too. Just because a function says in its declaration line that it returns values doesn't mean you have to request them when calling it.
  1 个评论
Patrick
Patrick 2012-11-4
Great! I always thought that you have to have return value for the function. Thanks!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by