Undeclared function or variable.
조회 수: 4 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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.
댓글 수: 0
추가 답변 (1개)
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));
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!