Effacer les filtres
Effacer les filtres

How to interpolate values given a starting and end point

9 vues (au cours des 30 derniers jours)
Bradley
Bradley le 14 Juin 2024
Déplacé(e) : Voss le 14 Juin 2024
I have a voltmeter that I was using to measure voltage on a battery, unfortunatly it wasnt working properly and Im not able to do the test again. Before and after I ran the test I tested the voltage, so I know the real starting (50.6V) and ending (50.3V). My voltmeter recorded the power draw correctly but the values are off, they hover around 18V, how do I interpolate the bad values with a known starting and end point?
Example:
I know its 50.6 to 50.3 and my recordings are 18.2 to 17.9
I want the readings to be 50.6, 50.5, 50.4, 50.3 instead of 18.2, 18.1, 18.0, 17.9. I cant just add the difference because power draw wasnt exactly linear so Im trying to use the interp1 function but it isnt working for me. Thanks!
  1 commentaire
Voss
Voss le 14 Juin 2024
Déplacé(e) : Voss le 14 Juin 2024
xl = [18.2, 17.9];
yl = [50.6, 50.3];
real_values = (recordings-xl(1))./(xl(2)-xl(1)).*(yl(2)-yl(1))+yl(1);

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 14 Juin 2024
Use the rescale function —
Vrec = [18.2, 18.1, 18.0, 17.9];
Vrange = [50.6 50.3];
Vres = rescale(Vrec, Vrange(2), Vrange(1))
Vres = 1x4
50.6000 50.5000 50.4000 50.3000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
.
  2 commentaires
Bradley
Bradley le 14 Juin 2024
This worked great, thank you!
Star Strider
Star Strider le 14 Juin 2024
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (1)

John D'Errico
John D'Errico le 14 Juin 2024
If you ONLY have two data points, the only possible interpolation is LINEAR. There is no fancy method to interpolate in a nonlinear way. Interp1 cannot help you.
Caveat: You could perform a sort of exponential interpolation, so a nonlinear interpolant. Effectively, that means you might take the log of your data, then use linear interpolation, then use exp to back out the logs.
As far as why interp1 was not working for you, we cannot guess, because we do not see what you did with interp1, how you called it. We cannot see into your computer, or read your mind.

Tags

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by