Advanced Plotting of graphs

13 ビュー (過去 30 日間)
Clemens
Clemens 2014 年 7 月 15 日
コメント済み: Yoav Livneh 2014 年 7 月 15 日
Hello everyone,
i wrote a matlab simulation for a traffic scenario. I have multiple vehicles on a road and a time.
The simulation ends up providing a v-t and a s-t diagramm.
As I need to plot them I was wondering if the following is possible:
One x axis (position/s) and two y - axis (speed and time) with the velocity pointing upwards and the time downwards. So I could look at the "bottom graph" where my vehicle is at a given time and then, by just moving straight up, see the actial velocity at this point.
For that I need to tranform the v-t data into s-t but this shouldn't be a problem so far I'm having trouble to get the graphs looking like this and the axis set up.
Is there anyone who has an idea how to realise this?
Thanks very much in advance

採用された回答

Clemens
Clemens 2014 年 7 月 15 日
Thanks for your reply. Yes i've already used the plotyy command but as you say unfortunately it doesn't give me two seperated plots.
Do you know if it's possible via subplots? Is there any way to remove th egap between two plots? Then I'd just need to turn one axis around and hide the other x axis this shouldn't be too difficult, right?
  1 件のコメント
Yoav Livneh
Yoav Livneh 2014 年 7 月 15 日
Yes you can use subplot:
figure;
ax1=subplot(2,1,1);
plot(s,v);
ax2=subplot(2,1,2);
plot(s,t);
set(ax2,'XAxisLocation','top','YAxisLocation','right');
You can also do
set(ax2,'YDir','reverse');
if you want to reverese the order of the time y axis.
Now you can play with the position property of ax2 to make them align.

サインインしてコメントする。

その他の回答 (1 件)

Yoav Livneh
Yoav Livneh 2014 年 7 月 15 日
You can use the plotyy command to plot two y axes with the same x axis. For example:
[AX, H1, H2] = plotyy(s,v,s,t);
This will not give you a "bottom" graph but will put both of them together with different y-axes and colors.

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by