MATLAB: How to have presistent physical constants

constantsMATLAB

Hello,
I know Matlab can do pi. I would also like to add values for other constants such as electron charge, Boltzman constant, etc. and simply have them accessible as ec and kb. However, I don't want them to get wiped out when I do a "clear all" command, so simply defining them in startup.m isn't what I want. Basically, I want them to be treated just like how Matlab treats pi (i.e. they still exist even after I clear all variables). Is there a simple way to do this?
Thanks

Best Answer

If you want to do it the way pi is done, then create your own function files. E.g.,
% File ec.m on the path
function result = ec
result = 1.6021766208e-19;
end
and separately,
% File kb.m on the path
function result = kb
result = 5.670367e-8;
end
However, as Walter mentions, it might be better to package all of your constants up into a single variable (e.g., struct) that can be imported via a single function.