How to convert this code without 'goto' statement?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Since goto statement is not valid in matlab, how can I use the following code written in embedded matlab function:
function y = fcn(clk, lfsr)
jump :
upperT=1000;
count=1;
T=666;
y=1;
label :
if clk==1
Ton=0.806*T;
if Ton<T
y=1;
if count<Ton
count=count+1;
goto label;
elseif Ton<count<T
y=0;
count=count+1;
goto label;
elseif count>T
count=1;
T=lfsr+upperT;
goto label;
else
goto jump;
end
else
goto jump;
end
else
goto jump;
end
end
0 Commenti
Risposte (1)
Roger Stafford
il 4 Nov 2014
Modificato: Roger Stafford
il 4 Nov 2014
That is code you wouldn't want to use. As it stands the function has no way to exit. Regardless of the results of all the 'if', 'elseif' and 'else' conditions, it would always jump back to either "label" or "jump".
Be assured that valid code (which this isn't) can always be transformed so that it would avoid having to do a 'goto', though in some cases it might become somewhat more complicated. Actually this code can be revised so as to avoid goto's but I prefer not to waste time on it because of its erroneous nature.
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!