MATLAB: Having trouble with interp2 within a for loop

using for loop with interp2

Hello, I'm having a little issue with my for loop using interp2:
%For enthalpy given the temperature and pressure
p1 = 20:0.03:200;
t1 = 5:1:500;
for i = 1:length(p1)
for j = 1:length(t1)
rho(i,j) = interp2(p1,t1,rho_ph)
end
end
%For density given the pressure and enthalpy
p2 = 500:1:1100;
t2 = 200;
for k = 1:length(p2)
for l = 1:length(t1)
h_pt(k,l) = interp2(p2,t2,h_pt)
end
end
This is the error:
Error using griddedInterpolant
Interpolation requires at least two sample points in each dimension.
Error in interp2/makegriddedinterp (line 214)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 111)
F = makegriddedinterp({X,Y},V,method,extrap);
I'm not really understanding what is being asked.

Best Answer

You have
rho(i,j) = interp2(p1,t1,rho_ph)
p1 is a vector. t1 is a vector. rho_ph we do not know the size of.
The two allowable ways to call interp2 are:
interp2(DataGrid, Row_query_points, Column_query_points)
and
interp2(X_information, Y_information, DataGrid, X_query_points, Y_query_points)
In the first of those two syntaxes, the one you used, the first parameter, the DataGrid, must be at least 2 x 2, but you are passing in a vector for the first part.
In the second of those two syntaxes, it is permitted for X_information and Y_information to be vectors, but you need to specify the places that you want the queries to be at.