How do I plot y(t) vs x(t) for all t in MATLAB?

There are two functions, x(t) and y(t) that I have as a said of data points, and t which is a vectors of times running from 0 to 30 in 2s intervals (i.e. t = 0:2:30
Both x and y are vectors that correspond to a set of points at each time t - x being the position in the x-direction at time t and y being the position in the t direction at time t.
Therefore, the 3 vectors x y t are all the same length.
So how do I plot y vs x for all t.
Ezplot does not work because I don't have an actual function (e.g. x^2 or e^x), but rather a set of points.
Thanks!!

 Accepted Answer

plot3(t,x,y)

10 Comments

Thanks for the answers, but that's not what I'm looking for.
When I saw the figure that solution should give, it looks like a colourful shape in 3d.
plot3(t,x,y) I already tried and does not give the correct output.
Any other suggestions? Maybe plotting as mesh or in 3d some other way to get the correct shapes and colours. Or surf or something like that because the correct solution should give something that looks like it's made up of lots of contour lines. I'm just making random suggestions though.
Thanks.
You said t,x and y are same length
They are the same length (i.e. have the same number of elements).
In the output to plot3(t,x,y), you get a single curve. The best way I can describe the correct output is many of those curves that made it look 3d.
Maybe you should reshape your array to get 3 matrices, t,x and y and use mesh or surf function.
How would I do that?
What do you mean by reshape?
Can you a sample of your data?
t=0:2:30;
x = [61 72.8 81.9 87.9 90.9 90.8 87.3 80.5 70.4 56.9 39.9 19.4 -4.6 -32.2 -63.3 -98];
y = [65 46.7 30.3 15.8 3.2 -7.4 -15.8 -22.1 -26.2 -28.1 -27.9 -25.3 -20.5 -13.4 -4.1 7.6];
I have to plot y vs x for all t.
The correct output is the figure in the link I gave you.
n=size(t,2)
tt=repmat(t,n,1)
xx=repmat(x,n,1)'
yy=repmat(y,n,1)'
surf(tt,xx,yy)
Thanks a lot man!!

Sign in to comment.

More Answers (1)

Thanks for the answers, but that's not what I'm looking for.
When I saw the figure that solution should give, it looks like a colourful shape in 3d.
plot3(t,x,y) I already tried and does not give the correct output.
Any other suggestions? Maybe plotting as mesh or in 3d some other way to get the correct shapes and colours.
Thanks.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!