interp2 problem in size dimesion
이전 댓글 표시
I want to make cubic spline for density as function of P and T , I tried to use interp2 to evaluate density at specific p and T but I got the error of Interpolation requires at least two sample points for each grid dimension.
Here is the code
num = readtable("co2_T.xls");
P= table2array(num(:,1));% first column
T= table2array (num(:,2));%second column
z= table2array (num(:,5));% third column
v3=interp2(P,T,z,14.7,120)
답변 (1개)
Your problem is you are trying to use the wrong tool. interp2 allows you to interpolate in two dimensions, but ONLY for data that lies on a grid in those variables. You have what is commonly known as scattered data. So you need to use a tool that can perform interpolation on scattered data.
help scatteredInterpolant
Of course, you are asking to do a cubic spline interpolation, and scatteredInterpolant does not have that as an option. Instead, you can do a little better using griddata. As you can see, griddata does off a cubic interpolant, though I think I recall it is not a true cubic spline, in the sense of being twice differentiable everywhere. Even so, it may be sufficient for your needs. Or you can use the 'v4' method, which is also smooth, though it has been some time since I looked at it to remember the exact nature of that interpolation method.
help griddata
카테고리
도움말 센터 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!