Is using global variables for additional parameters in a callback function safe for deployment?
이전 댓글 표시
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:
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 MATLAB Compiler SDK에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!