how to get Y Value from a plot having 3 curves as shown in figure?

9 Ansichten (letzte 30 Tage)
Hi all,
Please give me method to solve this problem either in script or App Designer any method is lot of helpful.
Question Described : I have a plot with multiple curve (Image attached).
Input i have X axis and Curve Data, for this i need to get Y value.
Plot looks like this. see Attachment >> Now For X value (@ point Q between P1 & P2) I should find Y.
Here If i give 2 inputs
Input1 >> data of P1,P2 Or P3 Or inbetween P1 & P2
input2>> X value
Output Requried Y >> for above inputs.
Thanks for Help.

Akzeptierte Antwort

Star Strider
Star Strider am 30 Aug. 2021
Try something like this —
x = linspace(0, 5);
C1 = 5+(x-2).^2;
C2 = 2+(x-1).^4;
xint = interp1(C1-C2, x, 0)
xint = 2.3275
yint = interp1(x, C1, xint)
yint = 5.1074
figure
hp1 = plot(x, C1);
hold on
hp2 = plot(x, C2);
plot([0 xint], [1 1]*yint, '--k')
plot([1 1]*xint, [0 yint], '--k')
hp3 = plot(xint, yint, 'xg', 'MarkerSize',15);
hold off
grid
legend([hp1,hp2,hp3], 'C_1', 'C_2', 'Intersection', 'Location','best')
ylim([0,15])
I have no idea if your curves are functions or data. If they are functions, it would be necessary to evaluate them first to use this code. (If they are functions and you want to evaluate the intersections as functions, you would need to use fzero or fsolve.)
.
  6 Kommentare
naveen kumar s
naveen kumar s am 2 Sep. 2021
@Star Strider Really appreciate your valuable time.
Yes I have to use Scattered interpolant.
I tried but still its not working i knew i made somewhere mistake findind it. (even i will attach code also)
I have attached plot from matlab after running code.
@ inputs Xq @ different P. >> i got output but it is taking at X axis but not taking P.
alldata = load ('MPpsy.mat');
save('MPpsy.mat','-struct','alldata');
r = 50;
% curves of P5 to Pn x & y values are not in same size.
X1 = (linspace(alldata.p5(1,1), alldata.p5(end,1),r))';
Y1 = interp1(alldata.p5(:,1),alldata.p5(:,2),X1,'linear');
X2 = (linspace(alldata.p6(1,1), alldata.p6(end,1),r))';
Y2 = interp1(alldata.p6(:,1),alldata.p6(:,2),X2,'linear');
X3 = (linspace(alldata.p7(1,1), alldata.p7(end,1),r))';
Y3 = interp1(alldata.p7(:,1),alldata.p7(:,2),X3,'linear');
X4 = (linspace(alldata.p8(1,1), alldata.p8(end,1),r))';
Y4 = interp1(alldata.p8(:,1),alldata.p8(:,2),X4,'linear');
X5 = (linspace(alldata.p9(1,1), alldata.p9(end,1),r))';
Y5 = interp1(alldata.p9(:,1),alldata.p9(:,2),X5,'linear');
X6 = (linspace(alldata.p10(1,1), alldata.p10(end,1),r))';
Y6 = interp1(alldata.p10(:,1),alldata.p10(:,2),X6,'linear');
X7 = (linspace(alldata.p12(1,1), alldata.p12(end,1),r))';
Y7 = interp1(alldata.p12(:,1),alldata.p12(:,2),X7,'linear');
X8 = (linspace(alldata.p14(1,1), alldata.p14(end,1),r))';
Y8 = interp1(alldata.p14(:,1),alldata.p14(:,2),X8,'linear');
X9 = (linspace(alldata.p16(1,1), alldata.p16(end,1),r))';
Y9 = interp1(alldata.p16(:,1),alldata.p16(:,2),X9,'linear');
X10 = (linspace(alldata.p18(1,1), alldata.p18(end,1),r))';
Y10 = interp1(alldata.p18(:,1),alldata.p18(:,2),X10,'linear');
X11 = (linspace(alldata.p20(1,1), alldata.p20(end,1),r))';
Y11 = interp1(alldata.p20(:,1),alldata.p20(:,2),X11,'linear');
X12 = (linspace(alldata.p25(1,1), alldata.p25(end,1),r))';
Y12 = interp1(alldata.p25(:,1),alldata.p25(:,2),X12,'linear');
X13 = (linspace(alldata.p30(1,1), alldata.p30(end,1),r))';
Y13 = interp1(alldata.p30(:,1),alldata.p30(:,2),X13,'linear');
X14 = (linspace(alldata.p35(1,1), alldata.p35(end,1),r))';
Y14 = interp1(alldata.p35(:,1),alldata.p35(:,2),X14,'linear');
X15 = (linspace(alldata.p40(1,1), alldata.p40(end,1),r))';
Y15 = interp1(alldata.p40(:,1),alldata.p40(:,2),X15,'linear');
X16 = (linspace(alldata.p50(1,1), alldata.p50(end,1),r))';
Y16 = interp1(alldata.p50(:,1),alldata.p50(:,2),X16,'linear');
X17 = (linspace(alldata.p60(1,1), alldata.p60(end,1),r))';
Y17 = interp1(alldata.p60(:,1),alldata.p60(:,2),X17,'linear');
X18 = (linspace(alldata.p70(1,1), alldata.p70(end,1),r))';
Y18 = interp1(alldata.p70(:,1),alldata.p70(:,2),X18,'linear');
X19 = (linspace(alldata.p80(1,1), alldata.p80(end,1),r))';
Y19 = interp1(alldata.p80(:,1),alldata.p80(:,2),X19,'linear');
X20 = (linspace(alldata.p90(1,1), alldata.p90(end,1),r))';
Y20 = interp1(alldata.p90(:,1),alldata.p90(:,2),X20,'linear');
X21 = (linspace(alldata.p100(1,1), alldata.p100(end,1),r))';
Y21 = interp1(alldata.p100(:,1),alldata.p100(:,2),X21,'linear');
X22 = (linspace(alldata.p120(1,1), alldata.p120(end,1),r))';
Y22 = interp1(alldata.p120(:,1),alldata.p120(:,2),X22,'linear');
X23 = (linspace(alldata.p150(1,1), alldata.p150(end,1),r))';
Y23 = interp1(alldata.p150(:,1),alldata.p150(:,2),X23,'linear');
X24 = (linspace(alldata.p200(1,1), alldata.p200(end,1),r))';
Y24 = interp1(alldata.p200(:,1),alldata.p200(:,2),X24,'linear');
X25 = (linspace(alldata.p250(1,1), alldata.p250(end,1),r))';
Y25 = interp1(alldata.p250(:,1),alldata.p250(:,2),X25,'linear');
X26 = (linspace(alldata.p300(1,1), alldata.p300(end,1),r))';
Y26 = interp1(alldata.p300(:,1),alldata.p300(:,2),X26,'linear');
xx = [X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21 X22 X23 X24 X25 X26];
yy = [Y1 Y2 Y3 Y4 Y5 Y6 Y7 Y8 Y9 Y10 Y11 Y12 Y13 Y14 Y15 Y16 Y17 Y18 Y19 Y20 Y21 Y22 Y23 Y24 Y25 Y26];
zz =linspace(5,300,50);
% zz = [5 6 7 8 9 10 12 14 16 18 20 25 30 35 40 50 60 70 80 90 100 120 150 200 250 300];% Trail check
X_axes= input('X = ');
P_curves= input('P = ');
P_x = interp1(zz,xx,P_curves,'linear','extrap');
P_y = interp1(zz,yy,P_curves,'linear','extrap');
Y = interp1(P_x,P_y,X_axes,'linear','extrap')
plot(xx,yy)
axis([-50 100 0 0.034])
hold on
plot(X_axes,humidity,'*')
here is code .
New Question :
Here i used my mat file saved as struct. ( for all P curves, X &Y are in different size : So X1 Y1 to X26 Y26 did interpolation to maintain size. >> Can I Do This Using FOR function Less Steps.
&
Yes finally what mistake in my code why I am not getting Y exactly.
Star Strider
Star Strider am 2 Sep. 2021
That is very difficult for me to follow.
Also, there is no plot.
With respect to using a for loop, that is definitely a possibility. However, it would be necessary to use struct2cell or struct2table (if possible) to extract the structure to some sort of array, since structures themselves would be difficult (or impossible) to index in a loop (at least for me, since I have never tried it).
.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

KALYAN ACHARJYA
KALYAN ACHARJYA am 30 Aug. 2021
Bearbeitet: KALYAN ACHARJYA am 30 Aug. 2021
I have assumed that you have the 3 data for three individual plot, with respect to same x values, let say y1,y2,y3 for the same value of x
val1=abs(y1-y2)
idx=find(val1==min(val1)) %Get the index of first intersection of y1 & y2
x_id1=x_data(idx);
Do the same for other plot, also you may look for other solutions too-
  2 Kommentare
naveen kumar s
naveen kumar s am 31 Aug. 2021
thank you so much. I will try this give you me feedback.
naveen kumar s
naveen kumar s am 31 Aug. 2021
Actually,
The plot Above Shown is just Example ;
In my Plot there is no Intersection of all curves.
Plot looks like this. see Attachment >> Now For X value (@ point Q between P1 & P2) I should find Y.
Here If i give 2 inputs
Input1 >> P1,P2 Or P3 Or inbetween P1 & P2
input2>> X value
Output Requried Y >> for above inputs.
@KALYAN ACHARJYA This is my actual Question. I will update above also.
Thanks for your help.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by