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!