x-axis difference between two graphs

15 vues (au cours des 30 derniers jours)
Hasan canar
Hasan canar le 27 Fév 2021
Modifié(e) : dpb le 1 Mar 2021
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 commentaires
dpb
dpb le 27 Fév 2021
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
Hasan canar
Hasan canar le 1 Mar 2021
You may find the Red and Black data text files as attachment.

Connectez-vous pour commenter.

Réponses (1)

dpb
dpb le 1 Mar 2021
Modifié(e) : dpb le 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?

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by