Hello, I'm trying to interpolate a polynomial function through a set of points obtained from a simulation. However I'm always getting the error "Z must be a matrix, not a scalar or vector" even though Z is actually a Matrix. And also getting the error:
in lagrange2D (line 43)
surf(x(1):(x(end)-x(1))/(size(A,1)-1):x(end),y(1):(y(end)-y(1))/(size(A,1)-1):y(end),A);
I have this data
xh =
Columns 1 through 9
0.0112 0.0112 0.0112 0.0112 0.0112 0.0112 0.0112 0.0090 0.0090
Columns 10 through 18
0.0090 0.0090 0.0090 0.0090 0.0090 0.0140 0.0140 0.0140 0.0140
Columns 19 through 27
0.0140 0.0140 0.0140 0.0135 0.0135 0.0135 0.0135 0.0135 0.0135
Columns 28 through 36
0.0135 0.0075 0.0075 0.0075 0.0075 0.0075 0.0075 0.0075 0.0064
Columns 37 through 45
0.0064 0.0064 0.0064 0.0064 0.0064 0.0064 0.0106 0.0106 0.0106
Columns 46 through 49
0.0106 0.0106 0.0106 0.0106
and then the function itself
function lagrange2D
N = 15;
xa = linspace(min(xh), max(xh), N);
ya = linspace(min(yh), max(yh), N);
[X,Y] = meshgrid(xa, ya);
Z = griddata(xh, yh, F1h, X, Y);
step = 0.2;
xCurves={};
for i=1:size(X,1)
x = X(i,:)';
z = Z(i,:)';
p=[];
for j = x(1):step:x(end)
p = [p,lagrange(x,z,j)];
end
xCurves{i} = p;
end
y = Y(:,1);
A=[];
for i=1:length(xCurves{1})
p=[];
z=[];
for l=1:length(y)
z = [z;xCurves{l}(i)];
end
for j = y(1):step:y(end)
p = [p;lagrange(y,z,j)];
end
A = [A,p];
end
surf(x(1):(x(end)-x(1))/(size(A,1)-1):x(end),y(1):(y(end)-y(1))/(size(A,1)-1):y(end),A);
hold on;
end
Any thoughts on what am I doing wrong in here?
Thanks in Advance