フィルターのクリア

matlab command similar to EQU directive

1 回表示 (過去 30 日間)
Ganesh
Ganesh 2011 年 8 月 12 日
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.

採用された回答

Walter Roberson
Walter Roberson 2011 年 8 月 12 日
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...

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDownloads についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by