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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
//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 Kommentare
Antworten (2)
Steven Lord
am 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 Kommentare
Walter Roberson
am 30 Nov. 2016
I speculate that you might want to start with
persistent p
if isempty(p)
p = 0;
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu String finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!