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 view (last 30 days)
Show older comments
//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 Comments
Answers (2)
Steven Lord
on 30 Nov 2016
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 Comments
Walter Roberson
on 30 Nov 2016
I speculate that you might want to start with
persistent p
if isempty(p)
p = 0;
end
0 Comments
See Also
Categories
Find more on String in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!