Interpolation based on three arrays. Problem: entering values for two parameters to get a third gives me the nearest input data values (no interpolation).
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
dpb
2022-7-14
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
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!