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

조회 수: 1(최근 30일)
naveen kumar s
naveen kumar s 2021년 8월 30일
댓글: Star Strider 2021년 9월 2일
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.

채택된 답변

Star Strider
Star Strider 2021년 8월 30일
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
Star Strider
Star Strider 2021년 9월 2일
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).
.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2021년 8월 30일
편집: KALYAN ACHARJYA 2021년 8월 30일
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
naveen kumar s
naveen kumar s 2021년 8월 31일
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.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by