How to plott multiple graphs with two Y-axes?

1 回表示 (過去 30 日間)
R7 DR
R7 DR 2015 年 8 月 13 日
回答済み: alok dhaundiyal 2020 年 5 月 7 日
Hi,
Please suggest me how to write the code to plott multiple graphs with two Y-axes.
I have data sets like this...
X-axis data X1=[.....]; X2=[.....]; X3=[....];
First Y axis data A1=[.....]; A2=[.....]; A3=[.....];
second Y axis data B1=[.....]; B2=[.....]; B3=[.....];
This data produce totally six graphs, theree with Y axis one and three with Y axis two, please check the following image.
I am also attaching the excel file, please have a look.
Thanks

回答 (3 件)

Sebastian Castro
Sebastian Castro 2015 年 8 月 13 日
編集済み: Sebastian Castro 2015 年 8 月 13 日
There is a "plotyy" function which lets you have two separate y-axes on the left and right sides:
Since you have 6 plots (3 on each axis, you should be able to concatenate them into columns. For example:
x = (1:10)';
y1 = rand(size(x));
y2 = rand(size(x));
y3 = rand(size(x));
y4 = 100*randn(size(x));
y5 = 100*randn(size(x));
y6 = 100*randn(size(x));
plotyy(x,[y1 y2 y3],x,[y4 y5 y6]);
- Sebastian

R7 DR
R7 DR 2015 年 8 月 13 日
Hi
I tried with your suggestion, but it is shwoing the error like ''Error using horzcat Dimensions of matrices being concatenated are not consistent.''
  2 件のコメント
Sebastian Castro
Sebastian Castro 2015 年 8 月 13 日
Does your data have different x-coordinates too? The commands I shared with you assume that all of them share the same x data, and therefore also have the same number of elements in the y-axis.
You could use functions like "interp1" to interpolate the data such that they all use the same x vector and can be concatenated and plotted with plotyy. Otherwise, it may be a more involved solution...
- Sebastian
R7 DR
R7 DR 2015 年 8 月 13 日
Please check attached excel, so you can get an idea data.

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


alok dhaundiyal
alok dhaundiyal 2020 年 5 月 7 日
plotyy(x,[y1, y2, y3],x,[y4, y5, y6]); Try this

カテゴリ

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