Why I get Reference to a cleared variable x. in my code?

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];

댓글 수: 2

"Why I get Reference to a cleared variable x. in my code?"
Because for no reason at all you put
clc, clear all, close all
at the start of your function. Why use some commands in your function if you don't know what they are doing? How are these commands in any way related to the functionality of what you are writing?
He probably wrote this without a function wrapper and forgot to remove that line before adding the function definition, having decided to wrap that code in a call.

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2018년 3월 2일
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.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Entering Commands에 대해 자세히 알아보기

질문:

2018년 3월 2일

댓글:

2020년 4월 1일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by