plotting two different function in the same figure with ezplot
7 ビュー (過去 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.
0 件のコメント
採用された回答
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 件のコメント
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
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)'])
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!