MATLAB: Scatter3 extrapolating problem help

error 61scatter3

hello, i have problem with this short for loop, matlab reports error in last line, number 61, X, Y and Z must be vectors of the same length. Im doing extrapolation, and have 100 points, so i want to do it after each 5, or 10 for example. can someone help me to solve it… thanks
scatter3(x,y,z,'b');
hold on;
for k=[5,5,5]
F = scatteredInterpolant(x(1:k),y(1:k),z(1:l), 'nearest');
zt = F([x(k+1),y(k+1)]);
scatter3(x(k+1),y(k+1),zt, 'r');
end
hold on;

Best Answer

F = scatteredInterpolant(x(1:k),y(1:k),z(1:l), 'nearest');
defines F as an interpolant over 2 variables (x, y) returning z.
zt = F([x(k+1),y(k+1)]);
calls F with a single parameter that is a vector of length 2, instead of calling with two parameters.
zt = F(x(k+1),y(k+1));