MATLAB: Warning while overwriting a workspace variable

base workspaceMATLABworkspace

Hello all,
is there a way a notification (warning/error/log) be issue when a base workspace variable is overwritten?
Details:
I have number of constants and parameters defined in various .m scripts.
I fear there might be constants with different values in some of the files . So whenever a variable is overwritten, I want to have some alert/logging.
Is this possible?
Basically, if a variable to be added to the workspace already "exists", it (some hook function or so) should somehow notify.
Thanks

Best Answer

While you can do this for certain types of variables (create a class and have that class's delete method issue a warning when executed) I'd propose a different solution. Since you mention this is in the context of a Simulink® model, consider using one of the other data storage techniques described on this documentation page. I haven't used these techniques myself, but based on your use case it sounds like a data dictionary may be useful in sharing data between the various models the different people or groups of people have written.
Related Question