How to convert this code without 'goto' statement?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Roger Stafford
le 4 Nov 2014
Modifié(e) : Roger Stafford
le 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 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!