global variable and live script
6 次查看(过去 30 天)
显示 更早的评论
Hallo everyone
I am using a live script where I declaire global variable and assign a value to the global variable with the control feature (from live script)
It seems that the assigned values of the global variables are only passed to the function (where I call the global variables) when I delcaire the global variable in the live script after using the control features.
When I delcaire the global at the beginning of the live script the called global variable in the functions are empty (0x0).
Does someone know how to use this directly?
Here an example:
this does not work
global userinp_ask
userinp_ask = false; %% this should be a drop down control from live script
my_function(); % here I call the global in the function
this does work
u_ask = false; %% this should be a drop down control from live script
global userinp_ask
userinp_ask = u_ask
my_function(); % here I call the global in the function
function myfunction()
global userinp_ask
% do something with userinp_ask
end
0 个评论
回答(1 个)
Harsha Kalavakolu
2022-5-10
As per my understanding you want to know why in the first case global variable "userinp_ask" is showing value as empty(0x0).
If the global variable does not exist the first time you issue the global statement, it is initialized to an empty 0x0 matrix. In the first case as global variable is not created yet it stores 0X0 matrix as its value.
In the second case you are assigning a value directly to global variable instead of declaring an empty global variable, that is why it is not storing 0X0 matrix.
I do not see any problem in the 1st method as well after you run the code, as the global variable data will be overwritten from empty matrix to false.
For more information on global variables go through the below documentation.
https://www.mathworks.com/help/matlab/ref/global.html
Hope it Helps.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!