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!