Problem with GUI variables from workspace
Show older comments
Hello, I have a problem running my GUI. I am defining bunch of variables using "Edit Text". I am signing them to workspace using
assignin('base','variable_name',value);
Then I want to calculate some new variables using those defined in Workspace after Button in GUI is pressed, but when i press the Button I am getting an error that the variable which I want to use in calculation is not defined even though i can see this exact variable visible in Workspace.
The simplified code goes like this:
function zwrot_tp_o_Callback(hObject, eventdata, handles)
zwrot_tp_o=str2num(get(handles.zwrot_tp_o,'String'));
assignin('base','zwrot_tp_o',zwrot_tp_o);
the same way as shown above I am defining other variables. Then the Button:
function symuluj_Callback(hObject, eventdata, handles)
tmax=1000;
t= [1:tmax]';
x1= zeros(zwrot_tp_o-1,1);
x2= ster_o * ones(zwrot_tk_o - zwrot_tp_o,1);
x3= zeros(tmax-zwrot_tk_o,1);
x=vertcat(x1,x2,x3);
The error occurs in line where I calculate x1, it says that i have undefined "zwrot_tp_o" even though it is in workspace. So I tried defining that variable once again just above the x1 equation just like: zwrot_tp_o=500 and then it was accepting this variable but was giving the same error about next variable. Any ideas?
1 Comment
Rather than learning bad habits like assignin and evalin and global, why not learn how to program using fast, reliable and robust ways of passing data between workspaces?
Every beginner has a choice: to learn how to program well, or to write hack code that will cause more problems than it solves (e.g. your example code).
Read these to start learning how to write better code:
Accepted Answer
More Answers (0)
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!