MATLAB: Listing Filename of Axes into Listbox

guilistboxpushbutton

Good day!
I am working on a GUI which includes a list boxs, push buttons and a axes. In the axes, I've managed to load a certain image.
MY PROBLEM is that when I click the pushbutton, it should display the filename of the image displayed in the axes into the listbox and I have no clue how to start on that. Any help would be appreciated 😀

Best Answer

Jose - in your pushbutton callback you will want to access the set of strings in the list box, and append your new string (the file name) to this list. Something like the following can be done
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data = get(handles.listbox1,'String');
if isfield(handles,'filename')
if isempty(data)
data = {handles.filename};
else
data = [data ; handles.filename];
end
end
set(handles.listbox1,'String',data);
The above assumes that you have saved the name of the file to the handles structure in the field filename.