|
Hi,
You can try this with guide and that helps(see handles.output) with generating output on the command line.
With the given code, the checkbox callback does not produce the output on the command line for two reasons -
1) You have uiwait on the figure. So unless the first call returns , the other calls (callbacks) will not return. Delete uiwait statment first.
2) As far as I know,Callback routines do not return values. They can accept input arguments. So even if you delete or comment uiwait statement, the Output_picked_stsr variable will be assigned the right string values, but they will not be passed back to the command line. If your needs are simple, you can do this instead -
h_1 = uicontrol(fig,'Style','checkbox','Value',0,...
'String','First one','tag','h_1','Position',[10 275 275 25],...
'callback','get(findall(get(gcf,''userdata''),''value'',1),''string'')');
h_2 = uicontrol(fig,'Style','checkbox','Value',0,...
'String','Second one','tag','h_2','Position',[10 250 275 25],...
'callback','get(findall(get(gcf,''userdata''),''value'',1),''string'')');
h_3 = uicontrol(fig,'Style','checkbox','Value',0,...
'String','Third one','tag','h_3','Position',[10 225 275 25],...
'callback','get(findall(get(gcf,''userdata''),''value'',1),''string'')');
h_4 = uicontrol(fig,'Style','checkbox','Value',0,...
'String','Fourth one','tag','h_3','Position',[10 200 275 25],...
'callback','get(findall(get(gcf,''userdata''),''value'',1),''string'')');
Delete uiwait statement also. After that try running the function.
"Recep" <rbirgul@gmail.com> wrote in message <gu9gbl$njl$1@fred.mathworks.com>...
> Hi all,
> I have manually created a GUI to obtain strings of "checked" checkboxes (since I was not able to figure out a way to assign the output of "export2wsdlg" to a varaible; besides, I would like to be able to modify the positions of the checkboxes on the figure).
>
> The function works fine during execution, but somehow I could not assign the strings of the "checked" checkboxes to the variable "Output_picked_stsr". I was able to get them to the screen (by not using ; at the end of its line) but the function is not returning these values to the variable " Output_picked_stsr" . What is it that I am misising in the code given below? By the way, I have already tried "guidata" and "setappdata/getappdata" options; but somehow figure handle "fig" is not recognized. The same problem occurs if I put "fig" instead of "gcf" in the following line of the code:
>
> gather_all = get(gcf,'userdata');
>
> The problem is probably very easy but unfortunatley I can't see it.
> Any suggestions?
>
> function Output_picked_stsr = picked_strs(argument)
>
> if nargin == 0 ; argument = 'Start'; end
>
> Output_picked_stsr = [];
>
> switch argument
> case 'Start'
> fig = figure;
> set(fig,'units','pixels','pos',[400 250 500 300],...
> 'numbertitle','off','name','Obtain String from Multiple Checkboxes','menu','none');
>
> h_1 = uicontrol(fig,'Style','checkbox','Value',0,...
> 'String','First one','tag','h_1','Position',[10 275 275 25],...
> 'callback','picked_strs(''check_uncheck'');');
>
> h_2 = uicontrol(fig,'Style','checkbox','Value',0,...
> 'String','Second one','tag','h_2','Position',[10 250 275 25],...
> 'callback','picked_strs(''check_uncheck'');');
>
> h_3 = uicontrol(fig,'Style','checkbox','Value',0,...
> 'String','Third one','tag','h_3','Position',[10 225 275 25],...
> 'callback','picked_strs(''check_uncheck'');');
> h_4 = uicontrol(fig,'Style','checkbox','Value',0,...
> 'String','Fourth one','tag','h_3','Position',[10 200 275 25],...
> 'callback','picked_strs(''check_uncheck'');');
> %%%%%%%% CLOSE BUTTON %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> uicontrol(fig,'style','push','string','Close now','back',[.6 .7 .8],...
> 'fore','red','pos',[30 50 75 30],...
> 'callback','fclose all;close;');
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> set(fig,'userdata',[h_1 h_2 h_3 h_4]) ;
> uiwait(fig);
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> case 'check_uncheck'
> gather_all = get(gcf,'userdata');
> Output_picked_stsr = get(findall(gather_all,'value',1),'string')
> end
|