How to get varargout to output text from pushbuttons in Matlab GUI? -


i trying create gui using guide allows user pick 1 of 2 pushbuttons. strings in pushbuttons vary each time (i haven't automated yet), when of pushbuttons pushed, i'd gui put out string output variable.

i have code shows output in workspace, handles deleted before outputfn called. suggestions on how fix this?

also, i'd use 'next' button. ideally should pull next 2 texts displayed on pushbuttons, in iterative manner, i'd happy move past hurdle of getting output now.here have far:

function varargout = select_a_b(varargin) % select_a_b matlab code select_a_b.fig %      select_a_b, itself, creates new select_a_b or raises existing %      singleton*. % %      h = select_a_b returns handle new select_a_b or handle %      existing singleton*. % %      select_a_b('callback',hobject,eventdata,handles,...) calls local %      function named callback in select_a_b.m given input arguments. % %      select_a_b('property','value',...) creates new select_a_b or raises %      existing singleton*.  starting left, property value pairs %      applied gui before select_a_b_openingfcn gets called.  %      unrecognized property name or invalid value makes property application %      stop.  inputs passed select_a_b_openingfcn via varargin. % %      *see gui options on guide's tools menu.  choose "gui allows 1 %      instance run (singleton)". % % see also: guide, guidata, guihandles  % edit above text modify response select_a_b  % last modified guide v2.5 18-jun-2015 15:12:42  % begin initialization code - not edit gui_singleton = 1; gui_state = struct('gui_name',       mfilename, ...     'gui_singleton',  gui_singleton, ...     'gui_openingfcn', @select_a_b_openingfcn, ...     'gui_outputfcn',  @select_a_b_outputfcn, ...     'gui_layoutfcn',  [] , ...     'gui_callback',   []); if nargin && ischar(varargin{1})     gui_state.gui_callback = str2func(varargin{1}); end  if nargout     [varargout{1:nargout}] = gui_mainfcn(gui_state, varargin{:}); else     gui_mainfcn(gui_state, varargin{:}); end % end initialization code - not edit   % --- executes before select_a_b made visible. function select_a_b_openingfcn(hobject, eventdata, handles, varargin) % function has no output args, see outputfcn. % hobject    handle figure % eventdata  reserved - defined in future version of matlab % handles    structure handles , user data (see guidata) % varargin   command line arguments select_a_b (see varargin)  % choose default command line output select_a_b handles.output = hobject; handles.string = ''; if isempty(varargin)     varargin{1} = 1;     varargin{2} = 1; end text1 = varargin{1}; text2 = varargin{2}; = {'apple';'orange'}; b = {'football';'basketball'}; set(handles.pushbutton1,'string',a(text1)); % wait until we're ready set(handles.pushbutton2,'string',b(text2)); % wait until we're ready  % update handles structure guidata(hobject, handles);  % uiwait makes select_a_b wait user response (see uiresume) uiwait(handles.figure1);   % --- outputs function returned command line. function varargout = select_a_b_outputfcn(hobject, eventdata, handles) % varargout  cell array returning output args (see varargout); % hobject    handle figure % eventdata  reserved - defined in future version of matlab % handles    structure handles , user data (see guidata)  % default command line output handles structure varargout{1} = hobject; varargout{2} = handles.string;   % --- executes on button press in pushbutton1. function pushbutton1_callback(hobject, eventdata, handles) % hobject    handle pushbutton1 (see gcbo) % eventdata  reserved - defined in future version of matlab % handles    structure handles , user data (see guidata) selectedbutton = get(hobject,'string') set(handles.string,'string',selectedbutton); guidata(hobject, handles); close(gcf);  % --- executes on button press in pushbutton2. function pushbutton2_callback(hobject, eventdata, handles) % hobject    handle pushbutton2 (see gcbo) % eventdata  reserved - defined in future version of matlab % handles    structure handles , user data (see guidata) selectedbutton = get(hobject,'string') set(handles.string,'string',selectedbutton); guidata(hobject, handles); close(gcf);   function edit1_callback(hobject, eventdata, handles) % hobject    handle edit1 (see gcbo) % eventdata  reserved - defined in future version of matlab % handles    structure handles , user data (see guidata)  % hints: get(hobject,'string') returns contents of edit1 text %        str2double(get(hobject,'string')) returns contents of edit1 double   % --- executes during object creation, after setting properties. function edit1_createfcn(hobject, eventdata, handles) % hobject    handle edit1 (see gcbo) % eventdata  reserved - defined in future version of matlab % handles    empty - handles not created until after createfcns called  % hint: edit controls have white background on windows. %       see ispc , computer. if ispc && isequal(get(hobject,'backgroundcolor'), get(0,'defaultuicontrolbackgroundcolor'))     set(hobject,'backgroundcolor','white'); end   % --- executes on button press in pushbutton3. function pushbutton3_callback(hobject, eventdata, handles) % hobject    handle pushbutton3 (see gcbo) % eventdata  reserved - defined in future version of matlab % handles    structure handles , user data (see guidata)   % --- executes during object creation, after setting properties. function pushbutton1_createfcn(hobject, eventdata, handles) % hobject    handle pushbutton1 (see gcbo) % eventdata  reserved - defined in future version of matlab % handles    empty - handles not created until after createfcns called 

i have answer question. summary of changes:

  • added uiresume (after adding uiwait in opening function) after each callback
  • deleted close (gcf) after each callback; if figure closes, hobject , handles in guidata no longer accessible output function
  • created handle structure contain text of interest , saved in guidata after each callback function
  • saved output guidata .mat file in output function

    % --- executes on button press in pushbutton1. function pushbutton1_callback(hobject, eventdata, handles) % hobject handle pushbutton1 (see gcbo) % eventdata reserved - defined in future version of matlab % handles structure handles , user data (see guidata) selectedbutton = get(hobject,'string') handles.string = selectedbutton; guidata(hobject, handles); uiresume(handles.figure1); % close(gcf);

    function varargout = select_a_b_outputfcn(hobject, eventdata, handles) % varargout cell array returning output args (see varargout); % hobject handle figure % eventdata reserved - defined in future version of matlab % handles structure handles , user data (see guidata) % default command line output handles structure varargout{1} = hobject; varargout{2} = handles.string; save 'guioutput' delete(hobject)

learnings post experience:

  • i should’ve been more specific regarding question. i’ll better more experience , learning correct ‘lingo’ use.
  • i should’ve pointed out in first post did spend considerable time looking @ multiple blogs , sites on matlab gui, guide, , guidata. frankly, none of sites found addressed specific question.
  • this post 1 helped me figure out mistake: http://www.mathworks.com/matlabcentral/answers/141809-issue-with-gui-editbox-callback

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -