Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a basic line plot in MATLAB?

Tags:

graph

plot

matlab

I have

a =

   54.1848
   50.0456
   99.9748
   83.1009
   63.1457
   91.7577
   64.0805
   48.2090
   75.7711

t =

   79.7077
   31.0913
   14.9389
   10.8303
   16.4844
   26.8465
   41.6946
   77.3369
  186.3246

How can make a simple line plot with a on y axis and t on x axis?

plot (a,t) gives

alt text

and plot (t,a) gives

alt text

I don't understand how these are generated. The result should be something else.

like image 868
Lazer Avatar asked Nov 20 '25 02:11

Lazer


2 Answers

[t_sorted, index] = sort(t);
plot(t_sorted, a(index));

is the most efficient way to do this.

Or, if you don't really care for having the lines you can simply use:

plot(t,a,'rx')
like image 120
Ofri Raviv Avatar answered Nov 23 '25 06:11

Ofri Raviv


I think that if you sort both vectors according to the values in t and then use plot(t,a) you will get what you want.

like image 25
Dana Avatar answered Nov 23 '25 05:11

Dana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!