How to plot multiple data sets in the same graph for a common range?

I have two sets of data for two curves. The first set is
x_Exp = [1.1;1.083;1.08;1.073;1.015;0.993;0.987;0.978;0.974;0.946;0.941;0.897];
y_Exp = [5.504201829;5.639866885;5.610055654;5.789536433;5.694270035;5.525332713;5.634467851;5.540490674;5.585972432;5.111549463;5.129729547;4.542420443];
The second set is
x_Model = [1.11111;1.05263;1;0.952381;0.909091;0.869565];
y_Model = [5.317717952;5.632039396;5.896917576;5.622196354;5.107126594;4.5305684];
How can i plot them in the same graph for a common range?
That means i need to find the the x_Model values which are smaller then x_Exp and then the corresponding y_Model values. It is easy to find the x_Model values that are smaller then x_Exp but how to find the corresponding values? How can i find those values so that i can plot them?

 採用された回答

Star Strider
Star Strider 2018 年 11 月 6 日

1 投票

If you want to have the two curves overlap as much as possible, this may work:
x_Shift = min(x_Model) - min(x_Exp);
figure
plot(x_Exp, y_Exp, x_Model-x_Shift, y_Model)
grid
It simply takes the minimum values of the two x-coordinates, and generates a shift value from it. This is then applied in the plot, leaving the original data unchanged.

7 件のコメント

madhan ravi
madhan ravi 2018 年 11 月 6 日
編集済み: madhan ravi 2018 年 11 月 6 日
+1,Thank you @Star strider was struggling :)
Mr. 206
Mr. 206 2018 年 11 月 6 日
編集済み: Mr. 206 2018 年 11 月 6 日
x_Model-x_Shift ans =
1.13855
1.08006
1.02744
0.97982
0.93653
0.89700
All the points are good except 1.13855 which is greater than the x_Model value.
Star Strider
Star Strider 2018 年 11 月 6 日
I have no idea what you want.
Try this instead, then:
y_Model_Intrp = interp1(x_Exp, y_Exp, x_Model, 'linear','extrap')
figure
plot(x_Exp, y_Exp, x_Model, y_Model_Intrp)
grid
It interpolates ‘x_Model’ to match the ‘x_Exp’ values, then plots them.
You will probably need to experiment to get the result you want.
Mr. 206
Mr. 206 2018 年 11 月 6 日
Ok, I am trying to make my problem more clear. This is the original plot with two curves together. The common x value for both of the curves are between 0.869565 to 1.1. I want both the graph within this range. I don't want to shift any graph which you did.
Star Strider
Star Strider 2018 年 11 月 6 日
After this, I am out of ideas:
x_Intrp = linspace(0.869565, 1.1, 500);
y_Model_Intrp = interp1(x_Model, y_Model, x_Intrp, 'linear','extrap');
y_Exp_Intrp = interp1(x_Exp, y_Exp, x_Intrp, 'linear','extrap');
figure
plot(x_Intrp, y_Exp_Intrp, x_Intrp, y_Model_Intrp)
grid
Mr. 206
Mr. 206 2018 年 11 月 6 日
Great! This worked fine.
Thank you so much.
Star Strider
Star Strider 2018 年 11 月 6 日
As always, my pleasure!

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 11 月 6 日

1 投票

x_Exp = [1.1;1.083;1.08;1.073;1.015;0.993;0.987;0.978;0.974;0.946;0.941;0.897];
y_Exp = [5.504201829;5.639866885;5.610055654;5.789536433;5.694270035;5.525332713;5.634467851;5.540490674;5.585972432;5.111549463;5.129729547;4.542420443];
x_Model = [1.11111;1.05263;1;0.952381;0.909091;0.869565];
y_Model = [5.317717952;5.632039396;5.896917576;5.622196354;5.107126594;4.5305684];
idx = any(x_Model) < x_Exp
plot(x_Model(idx),y_Model(idx),'-*c')

9 件のコメント

madhan ravi
madhan ravi 2018 年 11 月 6 日
編集済み: madhan ravi 2018 年 11 月 6 日
by logical indexing you can get desired values and plot use
hold on
after the first plot command in order to plot multiple graphs
Mr. 206
Mr. 206 2018 年 11 月 6 日
x_Model(idx)
1.11111
1.05263
1.00000
0.95238
0.90909
Here you can see in x_Model the value 1.11111 is clearly greater than 1.1 in the x_Exp!!!!
madhan ravi
madhan ravi 2018 年 11 月 6 日
so what should be the desired x_Model ?
Mr. 206
Mr. 206 2018 年 11 月 6 日
First i need to figure out which x_Model values are smaller or equal to x_Exp. Then need to figure out corresponding y_Model values. I don't know how to do that.
madhan ravi
madhan ravi 2018 年 11 月 6 日
I know what you mean but write those
x_Model values are smaller or equal to x_Exp
values explicitly so that I can code it according to the requirement
Mr. 206
Mr. 206 2018 年 11 月 6 日
So can you help me with this?
madhan ravi
madhan ravi 2018 年 11 月 6 日
give me sometime to figure it out
Mr. 206
Mr. 206 2018 年 11 月 6 日
Thank you so much for your help.
madhan ravi
madhan ravi 2018 年 11 月 6 日
Anytime :) , If you would have added this comment before I would have given the answer straight away

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

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

タグ

質問済み:

2018 年 11 月 6 日

コメント済み:

2018 年 11 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by