Interpolation based on three arrays. Problem: entering values for two parameters to get a third gives me the nearest input data values (no interpolation).

I have measured temperature, pressure, and volume of something and now have a file where there are three columns: T, P, and V. Each row gives me values that go together. For example:
S P V
90 475 1.0
40 200 1.06
20 200 0.84
40 70 1.02
10 70 0.91
I want to to do calculations where I can enter any S and P and get a V. Linear interpolation would be fine. I'm not experienced in statistics, so in case I'm not using the term correctly, what I mean is that I am fine with (for example) entering a S of 30, a P of 200, and having a V that falls halfway between 1.06 and 0.84.
I found a similar question from someone else and copied the answer:
However, there must be something I don't understand because I'm not getting any interpolation. What I mean is, if I enter any S and P, I'm ending up with a V that corresponds to the nearest S and P values that are record in my measurements. Is it that this is what SHOULD happen because I have used "nearest" as a specification? What could I do instead?
S = [90 40 20 40 10];
P = [475 200 200 70 70];
V= [1.0 1.06 0.84 1.02 0.91];
if true
a = S, P, V,'nearest');
pnt1 = a(80,100)
end

 Risposta accettata

You left out the most important part of the response there and didn't pay attention to one of the comments about use of 'nearest'
The above does nothing with syntax error on a missing parenthesis -- if the trailing parenthesis weren't there, it would assign S to variable a and then echo the values of P, V and the string 'nearest'. This would be of little, in ay benefit.
Following the lead there would be more like
S = [90 40 20 40 10].';
P = [475 200 200 70 70].';
V= [1.0 1.06 0.84 1.02 0.91].';
interp=scatteredInterpolant(S,P,V);
>> interp(20,200)
ans =
0.84
>> interp(80,100)
ans =
1.1552

Più risposte (0)

Categorie

Scopri di più su Interpolation in Centro assistenza e File Exchange

Prodotti

Release

R2021a

Richiesto:

il 14 Lug 2022

Risposto:

dpb
il 14 Lug 2022

Community Treasure Hunt

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

Start Hunting!

Translated by