File Exchange

image thumbnail

Define/Undefine Constants

version 1.0 (4.15 KB) by

Define and undefine constant variables with no use of global

3 Ratings



View License

these two functions define and undefine variable constants like the #define
preprocessor command in C.
No global variables are used.
Tested on R2006b
See help for each file

Comments and Ratings (3)

can baran

this .m file has a subtle bug that i didn't bother to fix. As the previous person commented it has troubles redefining (overwriting) the constants
The idea is a good one! It did save me the trouble of declaring global variables and invoking the global variables in subfunction where i need the global variables, but as it sometimes fails (and i dont know when exactly) to overwrite the constants, i stopped using this define.

m m

I seems to work good on Matlab 7.5, if you don't need to redefine during the execution.
(...on Matlab 7.5, I have troubles redefining constants, the value is not updated, even with 'undefine/define'...)

John D'Errico

An interesting idea. Nicely implemented.

I did get a chuckle over the example used - defining pi as 3. Some boards of education might even agree. 8-)

MATLAB Release
MATLAB 7.3 (R2006b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today