x-axis difference between two graphs

Hi everyone,
I am trying to take the x-axis difference of two graphs with same y- values. Fitting curves to data points do not work up to 9th degree polynomial.
My data points( shown in red dots) should be matched with black solid curve y data points but that curve should be taken into account as a curve instead of data points because its data points are far less than mine.
Im trying to do difference by drawing lines and calculating the dx but each plot has around 20 data points and I have 60 more plots to go. It hurts at some point.
I appreciate any help. Thanks

4 Comments

dpb
dpb on 27 Feb 2021
Edited: dpb on 27 Feb 2021
"My data points( shown in red dots) should be matched with black solid curve y data points ..."
Say what!!!??? No idea what you're trying to do given the explanation, sorry.
In particular, the sketch above shows an intersection of the LH side of the inverse peak, what is the desired actual result--that difference? That's doable simply with interp1 with the black curve data from LH end to the minima, but the double-valued nature of that curve presents a problem going past the minimum.
Also, it appears visually that the last few red points are less than the minimum of the black curve so there will be no intersection. What is supposed to happen then?
Attach the data and an illustration of what you think the revised values should be and how you arrived at that new value.
What I am trying to do is basically finding difference between two graphs in x-axis values.
You can neglect blue dots at right side of the vertical black line. My experimental datas are red dots and theoretical ones are blues ones. I need to find the shift between two graphs in terms of x-axis. One can do this by choosing any red dots and looking for the correspondent blue dot which has the same y value. You can see that blue and red dots are not intersects horizontaly so, I sketch blue dots as line as in introduction.
What can we do without the data? Attach the .mat file with the data...but, as noted earlier, using the red data as the wanted, and the blue as the interpolant, you should be able to get from interp1
[~,ix]=max(abs(B)); % find peak of Black data
B=B(1:ix); % the data left of minimum
v=interp1(B,BX,R); % the interpolated X value of B, given R
You may find the Red and Black data text files as attachment.

Sign in to comment.

Answers (1)

dpb
dpb on 1 Mar 2021
Edited: dpb on 1 Mar 2021
As suggested above, interp1 works just fine...
red=readtable('red.txt');black=readtable('black.txt'); % read data
plot(red.Var1,red.Var2,'ro','MarkerFaceColor','r') % plot to look at
hold on
plot(black.Var1,black.Var2,'ko','MarkerFaceColor','k')
ylim(ylim+[0 0.01]*1E-9)
xlim([-10 -4])
ired1=find(red.Var2<black.Var2,1); % locate first red point below black to start
[minblk,iblk]=min(black.Var2); % and have to stop at minimum of black
ired2=find(red.Var2<=minblk,1); % first point red less than the minimum
xq=interp1(black.Var2(1:iblk),black.Var1(1:iblk),red.Var2(ired1:ired2)); % find intersection red-->black
hLQ=plot(xq,red.Var2(ired1:ired2),'*b'); % plot result
results in
xq is, of course, the revised X to make each point match onto the black curve in turn. One can't do much about the remainder when lower than the black so don't intersect unless one were to scale the magnitudes as well.
The above uses default linear interpolation, one may want to experiment with alternative methods to produce a somewhat smoother curve around the knee.
Just out of curiosity, what do these data represent and why would a theoretical model and experiment differ in such a fashion?

Asked:

on 27 Feb 2021

Edited:

dpb
on 1 Mar 2021

Community Treasure Hunt

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

Start Hunting!