MATLAB Answers

0

check box, hey all, im wrote a code for creating a gui that contain checkbox and i cant take the data out of the function when i call it. what should i do?

Asked by Guni Basilian on 27 May 2019
Latest activity Commented on by Image Analyst
on 17 Jun 2019
this is the code:
function [tests]=gui_exsist_tests()
tmpcyc1=0; tmpcyc2=0; fpoint=0; sts=0; toto=0; linearity=0; noise=0; avar=0;
GUI_checkbox;
tests.tmpcyc1=tmpcyc1;
tests.tmpcyc2=tmpcyc2;
tests.fpoint=fpoint;
tests.sts= sts;
tests.toto=toto;
tests.linearity=linearity;
tests.noise=noise;
tests.avar=avar;
end
and this is the importent part from the GUI_checkbox
function checkbox3_Callback(hObject, eventdata, handles)
if get(hObject, 'Value')== get(hObject, 'Max')
fpoint=1;
else
fpoint=0;
end
assignin('base', 'fpoint', fpoint);
function checkbox4_Callback(hObject, eventdata, handles)
if get(hObject, 'Value')== get(hObject, 'Max')
sts=1;
else
sts=0;
end
assignin('base', 'sts', sts);
function checkbox5_Callback(hObject, eventdata, handles)
if get(hObject, 'Value')== get(hObject, 'Max')
toto=1;
else
toto=0;
end
assignin('base', 'toto', toto);
function checkbox6_Callback(hObject, eventdata, handles)
if get(hObject, 'Value')== get(hObject, 'Max')
linearity=1;
else
linearity=0;
end
assignin('base', 'linearity', linearity);
function checkbox7_Callback(hObject, eventdata, handles)
if get(hObject, 'Value')== get(hObject, 'Max')
noise=1;
else
noise=0;
end
assignin('base', 'noise', noise);
function checkbox8_Callback(hObject, eventdata, handles)
if get(hObject, 'Value')== get(hObject, 'Max')
avar=1;
else
avar=0;
end
assignin('base', 'avar', avar);
function pushbutton9_Callback(hObject, eventdata, handles)
close(gcf);

  3 Comments

Guni - I think that you need to clarify your steps. Are you launching the GUI checkbox from another GUI? And then you close this GUI and you wish to transfer the selections to the other GUI? Are both GUIs created with GUIDE? Please add some details.
yes, ive made this gui in guide and its wrote the code by itself. Unfortunately, I can not get it to interface with my function.
Attach your fig file and m file if you're still having a problem.

Sign in to comment.

1 Answer

Answer by Geoff Hayes
on 27 May 2019

Guni - rather than having your callbacks write data to the base workspace, you can have your GUIDE GUI output a (for example) structure that has fields for each of your checkboxes. Take a look at Advanced: Getting an output from a GUIDE GUI and the attached example. In your main function (that which calls the GUI) you could do something like
function [tests]=gui_exsist_tests()
checkboxData = GUI_checkbox;
tests.fpoint = checkboxData.fpoint;
% etc.
You would need to ensure that the output structure has the fields from each of your checkboxes, and that each field is named correctly.

  0 Comments

Sign in to comment.