Effacer les filtres
Effacer les filtres

matlab command similar to EQU directive

1 vue (au cours des 30 derniers jours)
Ganesh
Ganesh le 12 Août 2011
I have written a large program (almost 1500 lines). Now I need to change the parameters of one function which has been written in very initial part of the code. For example: say f(x,y) to f(x,y,z) Is there something like EQU directive which is used in many of assembly languages of microcontrollers? Please help. Thanks in advance.

Réponse acceptée

Walter Roberson
Walter Roberson le 12 Août 2011
No there is not.
Is there a default value that can reasonably be applied for z (perhaps calculated by x and y) ? If there is, then you can code
function f(x,y,z)
if ~exists('z','var')
z = ... %the default value
end
If this makes sense then you can make the changeover gradually, first doing the places were a different z is important, and then for consistency going back and filling in the ones were it is less important.
In the case where you know the name the variable would have in the calling code, you could use something like
function f(x,y,z)
if ~exists('z','var')
try
z = evalin('caller','z');
catch
z = ... %some default
end
end
I do not really comment this, but if it gets you through a crunch and you are sure you will be able to clean up the code afterwards... Note that if you just "intend" to clean up the code afterwards that chances are the code will stay warped, as there are always more things to do...

Plus de réponses (0)

Catégories

En savoir plus sur Downloads 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!

Translated by