MATLAB: I get Reference to a cleared variable x. in the code

cleared variable x

function data=surface_point(x,y)
clc, clear all, close all
px = [0 50 100 150 200 250 300; 0 50 100 150 200 250 300; 0 50 100 150 200 250 300; 0 50 100 150 200 250 300];
py = [0 0 0 0 0 0 0; 50 50 50 50 50 50 50;100 100 100 100 100 100 100;150 150 150 150 150 150 150];
pz = [-15 70 90 -60 -40 15 40; 40 -5 -20 -40 50 30 -20; 0 -45 -30 30 40 -10 -40; -30 5 50 0 -30 -20 20];
n=size(px,1)-1;
m=size(px,2)-1;
c=30;
u = x/300;
v = y/150;
for i=1:n+1
for j=1:m+1
sx=sx+px(i,j)*B(i-1,n,u)*B(j-1,m,v);
sy=sy+py(i,j)*B(i-1,n,u)*B(j-1,m,v);
sz=sz+pz(i,j)*B(i-1,n,u)*B(j-1,m,v);
end
end
data = [sx sy sz];

Best Answer

Because, although you pass in x and y, you delete them immediately with the command
clear all
Don't do that!!! If you don't do that, x will still be there when you need to use it.