필터 지우기
필터 지우기

Undeclared function or variable.

조회 수: 4 (최근 30일)
Khushank Singhal
Khushank Singhal 2017년 12월 17일
편집: Jan 2017년 12월 17일
When I run the function (given below), it shows an error:
" Undefined function or variable 'class_pointb'"
(The main code where the function is called is also attached. )
function counter = check(edge,point,n)
count_edge = zeros(1,10,4);
fit = 4;
interval = n / 10;
div = point(1,1) / interval;
for i = 1:10
if div >= i && div < i + 1
class_pointa = i;
break
end
end
div = point(1,2) / interval;
for i = 1:10
if div >= i && div < i + 1
class_pointb = i;
end
end
if edge(1) == 1
count_edge(1,class_pointa,1) = count_edge(1,class_pointa,1) + 1;
a = 1;
end
if edge(2) == 1
count_edge(1,class_pointb,1) = count_edge(1,class_pointb,1) + 1;
b = 1;
end
if count_edge(1,class_pointa,a) < fit && count_edge(1,class_pointb,b) < fit
counter = 1;
else
counter = 0;
end
end
I do not understand this because i think i have defined it as : class_pointb = i; How can it be corrected?

채택된 답변

KL
KL 2017년 12월 17일
Your condition div >= i && div < i + 1 probably never becomes true and so class_pointb is never defined. This is why initializing is good (with a zero maybe) and then you'll have to handle this value inside your count_edge function.

추가 답변 (1개)

Jan
Jan 2017년 12월 17일
편집: Jan 2017년 12월 17일
You can check this by using the debugger: https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html . Set a breakpoint in "class_pointa = i;" line and run the code again. You will see, that the condition is not met, as K L has explained already.
Using the debugger to examine code is essential for programming. It is even more efficient than asking the forum.
By the way: The loop might be less efficient then a vectorized approach:
% for i = 1:10
% if div >= i && div < i + 1
% class_pointa = i;
% break
% end
% end
% This can reply [] !!!
class_pointa = floor(div(div >=1 & div < 11));

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by