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?

1 次查看(过去 30 天)
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 个评论
Guni Basilian
Guni Basilian 2019-5-27
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.

请先登录,再进行评论。

回答(1 个)

Geoff Hayes
Geoff Hayes 2019-5-27
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.

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by