Help with interpolating - INTERP2
Show older comments
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 Comment
the cyclist
on 15 Feb 2012
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.
Accepted Answer
More Answers (1)
Sean de Wolski
on 15 Feb 2012
From:
doc interp2
X and Y must be monotonic
I was confused for a minute too. Use TriScatteredInterp.
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!