Listing Filename of Axes into Listbox

1 view (last 30 days)
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 :D

Accepted Answer

Geoff Hayes
Geoff Hayes on 17 Nov 2015
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.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!