In my models, I use a lot of dynamic masking to initialize parameters, which involves lots of long Callback functions. Also, creating/editing code in the Callback Editor seems to be very unpractical when the code is over a dozen lines long. A simple example of what I mean is as follows:
gear = {'1' '2' '3' '4' '5' 'R'};
angles = [0 10 20 25 30 -11];
str = get_param(gcb,'Position_final');
i = strcmp(str, Gear);
set_param(gcb,'Position_final_fine',angles(i));
This reads the value selected from a popup box, and changes the value of a spinbox so that angles between the selected value can also be used. This length code is manageable, but some of my Callback functions are over 400 lines long. As well as this, I will have now saved the parameters gear, angles, str and i in my workspace. Which with longer parts of code, turn into 20-30 parameters will quickly fill up my workspace. I could use clear, to clear the entire workspace (possibly damaging other parts of my model that rely on the workspace), or clear the parameters I have used, but then they would still overwrite parameters I have used (considering I use a lot of common acronyms and letters repeatedly).
One solution would be to create a function, and then have the Callback call the external function, which would increase readability of the code, and allow me to use multiple functions for similar Callbacks. However, then I will need to carry around many extra functions with the model, which I would rather avoid.
Is it possible to either,
1) create a separate workspace for the Callback function, in which it is not connected to the global workspace.
or
2) create a function that the Callback can access, and embed this in the Simulink .slx file, so that I do not need to carry round extra functions with the program.
Best regard,
Mathew