View License

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

» Watch video

Highlights from
Define/Undefine Constants

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

2.7 | 3 ratings Rate this file 0 Downloads (last 30 days) File Size: 4.15 KB File ID: #13622 Version: 1.0

Define/Undefine Constants



10 Jan 2007 (Updated )

Define and undefine constant variables with no use of global

| Watch this File

File Information

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

MATLAB release MATLAB 7.3 (R2006b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
16 Sep 2009 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.

19 Aug 2008 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'...)

12 Jan 2007 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-)

Contact us