8 views (last 30 days)

i want to plot cos(x) and sin(x) in the same figure, i have two ways :

i can write for example :

X=0:pi,

Y=cos(X);

Z=sin(X);

Plot(X,Y,X,Z)

or the second way :

X=0:pi;

Y=cos(X);

Z=sin(Z);

Plot(X,Y)

Hold on

Plot(X,Z)

what is the difference between these two ways ?

Honglei Chen
on 12 Dec 2017

If that's all you need, for the practical purpose, there isn't much difference. However, the internal settings in the two figures are different. For example, say you have another vector

W = cos(2*X);

and you want to plot it using

plot(X,W)

In the hold case, the new line will be added to the figure while in the other case, the axes will be cleared and the new plot contains only the new line.

HTH

Opportunities for recent engineering grads.

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

Start Hunting!
## 0 Comments

Sign in to comment.