MATLAB: How to exchange two plots (GUIDE)

guideplots

Hi, I have a GUIDE with two plots, and when I press a button, I want to exchange the curves ploted between the two of them. I made a code that "works" but plots the graphs one above the other (like a hold on). This is the code, what can I do to fix this?
graph1=handles.axes2;
axes_handle1 = findobj(graph1, 'Type', 'Axes');
axes_children_handle1 = get(axes_handle1, 'Children');
graph2=handles.axes3;
axes_handle2 = findobj(graph2, 'Type', 'Axes');
axes_children_handle2 = get(axes_handle2, 'Children');
copyobj(axes_children_handle2, handles.axes2);
copyobj(axes_children_handle1, handles.axes3);

Best Answer

Put each of the plots inside its own uipanel. Then to switch the plots, set the Parent property of the plot objects to be the other uipanel. Watch out for legend and colorbar as they are independent axes, not part of the axes like they appear to be.
Example:
set(handles.axes1, 'Parent', handles.uipanel2);
set(handles.axes2, 'Parent', handles.uipanel1);
drawnow();