tags:

views:

417

answers:

2

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.

+3  A: 

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.

Dana
+6  A: 
[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')
Ofri Raviv
Don't know why this was downvoted--it's the right answer!
Drew Hall
**sortrows()** is easier
Amro
BTW wasnt me who downvoted
Amro
One minor point: The OP said they want to plot `t` on the x axis and `a` on the y axis, so you just have to swap the two variables in your code.
gnovice
of course you are right. fixed. (also need to sort by t...)
Ofri Raviv