Help with interpolating - INTERP2
3 次查看(过去 30 天)
显示 更早的评论
Hi, I have a table with density values dependent on pressure and temperature, rho(p,T), and I want to be able to interpolate between them. I've tried using interp2, but I keep getting errors. This is an example (lot of numbers, but the code is easy):
p = [8*10^6 8*10^6 8*10^6 8*10^6 8*10^6 8*10^6 8*10^6 8*10^6 8*10^6;
10*10^6 10*10^6 10*10^6 10*10^6 10*10^6 10*10^6 10*10^6 10*10^6 10*10^6];
T = [280.000 300.000 305.000 310.000 315.000 320.000 325.000 330.000 350.000;
280.000 300.000 305.000 310.0000 315.000 320.000 325.000 330.000 350.000];
rho = [922.92 753.17 656.77 327.71 261.29 231.91 212.90 198.87 164.16;
938.22 801.62 751.67 685.77 586.02 448.28 358.04 310.25 228.80];
density = interp2(p, T, rho, 8*10^6, 280.00)
I keep getting the error: "X and Y must be matrices produced by MESHGRID. Use TriScatteredInterp instead of INTERP2 for scattered data." But if I try using TriScatteredInterp I get the error "Input data point locations have invalid dimension." I'm not able to understand what the problem really is. Can someone help me?
1 个评论
the cyclist
2012-2-15
Just as a side comment, I believe it is more accurate (and faster) to use the notation 8e6 rather than 8*10^6, which involves calculation.
采纳的回答
the cyclist
2012-2-15
Does this give what you expect?
density = interp2(p', T', rho', 8*10^6, 280.00)
Notice that I just transposed your inputs.
Or you could try TriScatteredInterp(), as suggested. In your case, the proper syntax is
F = TriScatteredInterp(p(:),T(:),rho(:));
density = F(8e6,280)
All in all, I think I would perform this calculation as:
p = [8e6 1e7];
T = [280 300 305 310 315 320 325 330 350];
[pp,TT] = meshgrid(p,T);
rho = [922.92 753.17 656.77 327.71 261.29 231.91 212.90 198.87 164.16;
938.22 801.62 751.67 685.77 586.02 448.28 358.04 310.25 228.80]';
density = interp2(pp,TT,rho,8e6,280.00)
0 个评论
更多回答(1 个)
Sean de Wolski
2012-2-15
From:
doc interp2
X and Y must be monotonic
I was confused for a minute too. Use TriScatteredInterp.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!