Clear Filters
Clear Filters

matlab command similar to EQU directive

1 view (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Aug 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...

More Answers (0)

Categories

Find more on Downloads 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!