Now that I'm actually in front of a computer with MATLAB...
I don't think you have a full understanding of what's going on with a GUI in MATLAB. Here's a basic programmatic GUI I'm going to use to illustrate some things:
function testbox
handles = initializeGUI;
resetList(handles)
XYarray = rand(10,2);
setappdata(handles.mainwindow,'XYarray',XYarray);
end
function [handles] = initializeGUI
handles.mainwindow = figure('MenuBar','None');
handles.button = uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[0.2 0.2 0.3 0.08], ...
'String','New Data Button', ...
'Callback',{@newdatabutton_fcn} ...
);
handles.button = uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[0.5 0.2 0.3 0.08], ...
'String','A Calculate Button', ...
'Callback',{@calculatebutton_fcn} ...
);
handles.listbox = uicontrol( ...
'Style','listbox', ...
'Units','normalized', ...
'Position',[0.2 0.3 0.6 0.6] ...
);
guidata(handles.mainwindow, handles);
end
function newdatabutton_fcn(hObject,~)
% Executes on button press
% Generates new XYarray data
handles = guidata(hObject);
resetList(handles)
XYarray = rand(10,2);
setappdata(handles.mainwindow,'XYarray',XYarray);
setappdata(handles.mainwindow,'intensity',[]);
end
function calculatebutton_fcn(hObject,~)
% Executes on button press
% Performs arbitrary calculation
handles = guidata(hObject);
resetList(handles)
XYarray = getappdata(handles.mainwindow,'XYarray');
intensity = XYarray(:,1)*5;
set(handles.listbox,'String',{intensity});
setappdata(handles.mainwindow,'intensity',intensity)
end
function resetList(handles)
% Clears the listbox
set(handles.listbox,'String','')
end
You'll notice that this looks slightly different than what you'll get using GUIDE but the functionality is exactly the same (See MATLAB's GUI documentation for the differences). In a GUIDE GUI, the majority of the initialization goes on behind the scenes. The two button_fcn subfunctions are analogous to your button press callback functions.
I've added a setappdata
call to generate some arbitrary data for the example, and a 'New Data' button to simulate loading in another image. Clicking on the calculate button clears the listbox, performs the calculation, updates the listbox, and saves the intensity data. Note how I'm using set()
to modify the properties of the listbox uicontrol object. The handles
structure is simply a collection of unique IDs that MATLAB uses to point to the various components of your GUI. By using get
and set
you can obtain and modify the various properties of your object. Of interest for a listbox is the string
property, which is the cell array of strings that is displayed.
Hopefully this example helps you to modify your GUI to have it do what you're expecting.