why I got error in MATLAB 2012a " Undefined function or variable 'p'. The first assignment to a local variable determines its class."when i run my code?
조회 수: 1 (최근 30일)
이전 댓글 표시
//This is my code
function p = fcn(GLE,s)
coder.extrinsic('pause');
p=p+1;
while (p<=4)
n=GLE;
end;
while ((p==1) && (n>=5))
g1=1;
r1=0;
y1=0;
g2=0;
r2=1;
y2=0;
g3=0;
r3=1;
y3=0;
g4=0;
r4=1;
y4=0;
n=n-1;
pause (1);
end
while ((p==1) && (n>0))
g1=0;
r1=0;
y1=1;
g2=0;
r2=1;
y2=0;
g3=0;
r3=1;
y3=0;
g4=0;
r4=1;
y4=0;
pause (1)
n=n-1;
end;
if (n==1)
a=2;
end
p = GLE;
p=s;
댓글 수: 0
답변 (2개)
Steven Lord
2016년 11월 30일
The variable p isn't defined the first time you try to use it in your function, on the line "p = p+1;". What exactly do you think the result of that command should be?
댓글 수: 0
Walter Roberson
2016년 11월 30일
I speculate that you might want to start with
persistent p
if isempty(p)
p = 0;
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 String에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!