plotting two different function in the same figure with ezplot

9 次查看(过去 30 天)
i am trying to plot the functions of y1(t)=t^2 and y2(t)=t^2-16 in the same range of (-8,8) with ezplot in the same figure window,i mean i would like to see these two curve simultaneously in the same figure window. how can i do this with ezplot?i have tried much ways but it gives me the solution in the different figure windows.i'd also like to do this with symbolic expressions.is it possible?
thank you.

采纳的回答

Paulo Silva
Paulo Silva 2011-7-23
ezplot supports only one expression for x and another for y so you must use two ezplots like this:
y1='t^2'
y2='t^2-16'
fg=figure
ax=axes;
ez1=ezplot(y1,[-8,8])
hold on
ez2=ezplot(y2,[-8,8])
legend('y1=t^2','y2=t^2-16')
set(ez1,'color',[1 0 0])
title(ax,['y1=t^2' ' y2=t^2-16'])
ezplot also doesn't support symbolic expressions so you must convert them to strings.
symbolic example:
syms t
y1=t^2
y2=t^2-16
fg=figure
ax=axes;
ez1=ezplot(char(y1),[-8,8])
hold on
ez2=ezplot(char(y2),[-8,8])
legend('y1=t^2','y2=t^2-16')
set(ez1,'color',[1 0 0])
title(ax,['y1=t^2' ' y2=t^2-16'])
The char function converts symbolic expressions to strings, you can also use the vectorize for the same purpose but it's different, vectorize adds dots before expressions like ^ and * so that operations like this t^2 where t is a vector won't fail because of the size of the vector, vectorize turn the symbolic expression t^2 into t.^2 , operations with the dot before the operation symbol are done element by element.
  2 个评论
murat artan
murat artan 2011-7-23
Yes,this is very critical:"hold on",now i remember.I think i never forget this anymore.
Thank you so much for your help.
Christopher Creutzig
Just a quick note for everyone finding this old reply now: MATLAB now has fplot as a more “modern,” hopefully easier to use, alternative to ezplot.

请先登录,再进行评论。

更多回答(1 个)

Abhinav Raman
Abhinav Raman 2018-8-21
f1='sin(x)' f2='cos(x)' ez1=ezplot(f1,[0,2*3.14]) hold on ez2=explot(f2,[0,2*3.14]) title(ax,['sin(x)','cos(x)'])

Community Treasure Hunt

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

Start Hunting!

Translated by