Is using global variables for additional parameters in a callback function safe for deployment?
Mostra commenti meno recenti
I am using a MATLAB function that requires me to use a callback function. However, my callback function takes some extra parameters that are not the default for this type of callback. To pass in my extra data, I've used global variables.
For example, here's some code that updates my plot using a 'lineCallback' with some additional parameters.
global lineStyle marker
lineStyle = '--';
marker = '*';
plot(x, y, 'ButtonDownFcn', @lineCallback);
And my callback function
function lineCallback(src, ~)
global lineStyle marker
src.Color = 'red';
src.LineStyle = lineStyle;
src.Marker = marker;
end
Now I would like to compile this code and deploy it using MATLAB Compiler. Is this safe to do?
I heard that usage of 'global' variables can be unsafe. Please run the below command in the command window of installed MATLAB R2019a version to get release specific documentation that describes this information:
>> web(fullfile(docroot, 'matlab/matlab_prog/share-data-between-workspaces.html'))
Please follow the below link to search for the required information regarding the current release:
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su MATLAB Compiler SDK in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!