MATLAB: Axes are not refreshing in Matlab GUIDE

guideplot fig in guipopupmenu

In a GUI application , placed a pop-up-menu, with two values 1 & 2. When the index of pop-up-menu is changed I want to plot a figure in gui ( not in a separate window) . Below code is written under pop-up-menu callback function, its working but the axis and titles are not updating or refreshing.
menuIndex = get(handles.popupmenu1, 'value');
figure;
if menuIndex == 1
plot(1:10);
title('title1');
else
plot(sin(1:10));
title('title2');
end
ax = findobj(gcf,'type','axes','-or','Tag','legend','-or','Tag','Colorbar');
hCopy= copyobj(ax, handles.figure1);

Best Answer

menuIndex = get(handles.popupmenu1, 'value');
fig = handles.figure1;
ax = axes('Parent', fig);
if menuIndex == 1
plot(ax, 1:10);
title(ax, 'title1');
else
plot(ax, sin(1:10));
title(ax, 'title2');
end
Nothing needs to be moved because it is all drawn in the proper figure in the first place.