luiv1616 - see the attached code for a quick example. In the GUI OpeningFcn, we create the plots and hide all but the first one
x = -2*pi:0.001:2*pi;
hold(handles.axes1, 'on');
h1 = plot(handles.axes1, x, sin(x), 'r', 'Visible', 'on');
h2 = plot(handles.axes1, x, cos(x), 'b', 'Visible', 'off');
h3 = plot(handles.axes1, x, tan(x), 'g', 'Visible', 'off');
We then update the list box with the plot names
listValues = {'sin', 'cos', 'tan'};
set(handles.listbox1, 'String', listValues');
and save the graphics objects handles to the handles struct
handles.plotHandles = [h1 h2 h3];
guidata(hObject, handles);
(The guidata call is important as it will save the updated handles struct with the new plotHandles member.)
In our list box callback, we just grab the index of the selected list item and set its corresponding graphics object visibility to ON (and turn all others to off)
selectedPlotIndex = get(hObject, 'Value');
set(handles.plotHandles(selectedPlotIndex), 'Visible', 'on');
for k=1:length(handles.plotHandles)
if k ~= selectedPlotIndex
set(handles.plotHandles(k), 'Visible', 'off');
end
end
Try the above and see what happens!
Best Answer