0

I have been trying to return some values from a GUI in MATLAB with 3 different Button Groups, like the example below, however none of the values are returned.

I tried to use global variables too, but this did not work either.

Any help would be appreciated.

 function mainUI(varargin)

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @mainUI_OpeningFcn, ...
                   'gui_OutputFcn',  @mainUI_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 - DO NOT EDIT

% --- Executes just before mainUI is made visible.
function mainUI_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;

guidata(hObject, handles);

uiwait(handles.gui);

% --- Outputs from this function are returned to the command line.
function varargout = mainUI_OutputFcn(hObject, eventdata, handles) 
    varargout{1} = handles.output;

% --- Executes when selected object is changed in SensorLocPanel.
function SensorLocPanel_SelectionChangeFcn(hObject, eventdata, handles)
    switch hObject
        ...
    end

% --- Executes when selected object is changed in StepTypeSel.
function StepTypeSel_SelectionChangeFcn(hObject, eventdata, handles)
    switch hObject
        ...
    end

% --- Executes when selected object is changed in FileSelectPanel.
function FileSelectPanel_SelectionChangeFcn(hObject, eventdata, handles)
    switch hObject
        ...
    end

    % --- Executes on button press in buttonRun.
function buttonRun_Callback(hObject, eventdata, handles) 
    clc;
    close all;
%     delete(handles.gui)
    return; % Quit the program

% --- Executes during object creation, after setting all properties.
function buttonChest_CreateFcn(hObject, eventdata, handles)


% --- Executes during object deletion, before destroying properties.
function buttonChest_DeleteFcn(hObject, eventdata, handles)

% --- Executes when user attempts to close gui.
function gui_CloseRequestFcn(hObject, eventdata, handles)
    if isequal(get(hObject,'waitstatus'),'waiting')
        uiresume(hObject);
        guidata(hObject,handles);
    else
        % The GUI is no longer waiting, so destroy it now.
        delete(hObject);
    end
user3666197
  • 1
  • 6
  • 50
  • 92
Leverz
  • 19
  • 4

1 Answers1

0

Is this gui done with GUIDE? In that case I recommend the following video tutorial to return values from a gui when it closes. If you want to return something from a gui to some other workspace while it runs (which I do not know why, but assumes that you have a valid reason for) I think that globals is an ok way at least. Notice however that you need to write the line

global <gVars>

in every function where you want to use global variables. The globals cannot be accessed every where as in some languages, they behave more like extern variables. However, the data from the global variables is f course stored in global workspace which means that in every function where you uses the global variable you can access the current value.

However, if I recall correctly there is a field in the figure called UserData that can take some user input data. It may be possible to define a struct there that contains all variables that you want to change. When you then need the data in the other workspace you just read it from this field.

patrik
  • 4,506
  • 6
  • 24
  • 48
  • Thank you Patrik, I'll look into UserData. – Leverz Oct 31 '14 at 23:06
  • Thank you Patrik, you where spot on with how I was missing the global variable declarations missing for individual functions. I got a chance to mess around to mess with it since. – Leverz Nov 01 '14 at 01:41