plotting two different function in the same figure with ezplot

7 ビュー (過去 30 日間)
murat artan
murat artan 2011 年 7 月 23 日
回答済み: Abhinav Raman 2018 年 8 月 21 日
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
Christopher Creutzig 2017 年 11 月 20 日
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)'])

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by