Hi,
i am just about creating my first complex GUI in MATLAB and i have one question plz. I created a GUI_1 that with the help of a push button starts a GUI_2. In GUI_2 the user can give some input values.
those input values (here for example the variable 'a') are given to the workspace with:
assignin('base', 'var1', a);
This works fine!
>> whoYour variables are:var1 var2
Now i want to have access to this variable that i named 'var1'. This access should be in a Callback from a push Button in GUI_1. Pressing this Push Button shall load the variables from workspace and start the main script.
I use the function 'evalin' for this:
function run__Callback(hObject, eventdata, handles)% hObject handle to run_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
temp1=evalin('base',var1)
Pushing the Push Button results in that error:
Undefined function or variable 'var1'.Error in Try1>run__Callback (line 259)temp1=eval('base',var1)Error in gui_mainfcn (line 96) feval(varargin{:});Error in Try1 (line 42) gui_mainfcn(gui_State, varargin{:});Error in @(hObject,eventdata)Try1('run__Callback',hObject,eventdata,guidata(hObject))Error while evaluating uicontrol Callback
How can it be? i checked the variables that are in the workspace and i saw that
function run__Callback(hObject, eventdata, handles) % hObject handle to run_ (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) who %temp1=evalin('base',var1)
results in
Your variables are:eventdata hObject handles
so why arent there var1 and var2 in the workspace anymore??? why are they lost…?
Best regards, John
Best Answer