How can I use local variable from GUI
Mostrar comentarios más antiguos
I created subroutine for my code named ' checkbox3' including 3 checkboxes. If I check a checkbox, it will return 1 and if not, it will return 0. For example, If I check the first and third box, I want it to return chk1=1;chk2=0;chk3=1. I really want these variables for my next step. I tried to use assignin function but it went to base workspace instead of my working workspace and I can't use these variable for my next step. So please give me some advice for this problem. Thank you very much! This is my code.
chk1=0;chk2=0;chk3=0;
assignin('base','chk1',chk1);assignin('base','chk2',chk2);... assignin('base','chk3',chk3);
% --- Executes on button press in checkbox1.
function chk1=checkbox1_Callback(hObject, eventdata, handles)
chk1=get(hObject,'Value');
assignin('base','chk1',chk1);
% --- Executes on button press in checkbox2.
function chk2=checkbox2_Callback(hObject, eventdata, handles)
chk2=get(hObject,'Value');
assignin('base','chk2',chk2);
% --- Executes on button press in checkbox3.
function chk3=checkbox3_Callback(hObject, eventdata, handles)
chk3=get(hObject,'Value');
assignin('base','chk3',chk3);
function pushbutton1_Callback(hObject, eventdata, handles)
close all
Respuesta aceptada
Más respuestas (1)
Azzi Abdelmalek
el 10 de En. de 2013
Editada: Azzi Abdelmalek
el 10 de En. de 2013
In opening function
chk123=[0 0 0];
set(handles.checkbox1,'userdata',chk123)
%In checkbox1 function
function chk1=checkbox1_Callback(hObject, eventdata, handles)
chk1=get(hObject,'Value');
chk123=get(handles.checkbox1,'userdata');
chk123(1)=chk1; % for chk2 it will be chk123(2)=chk2
set(handles.checkbox1,'userdata',chk123)
%or use guidata
%In opening function,
chk=[0 0 0];
handles.chk=chk;
guidata(hObject, handles);
%In checkbox1 function
chk1=get(hObject,'Value');
chk(1)=chk1;
handles.chk=chk
guidata(hObject, handles);
3 comentarios
Nopparat
el 10 de En. de 2013
Azzi Abdelmalek
el 10 de En. de 2013
In the last function
function pushbutton1_Callback(hObject, eventdata, handles)
chk=get(handles.checkbox1,'userdata');
a= chk(1); % error !!!
close all
% you also did an error in checkbox3_Callback, it's
chk123(3)=chk3 % instead of chk123(2)=chk2
Nopparat
el 11 de En. de 2013
Categorías
Más información sobre Scope Variables and Generate Names en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!