Copying all contents of a figure into another figure in Matlab GUIDE by clicking on a figure?
Show older comments
I have two sets of axes: (axes1_1, axes1_2) and (axes2_1, axes2_2). When I click on either of the sets, I would like to plot them both on a larger axes set (axes_large1, axes_large2), as shown in the image below. If either axes1_1 or axes1_2 are clicked, the axes1_1 should be traced on axes_large1 and axes1_2 should be traced on axes_large2. Same would be the case when axes2_1 and axes2_2 are clicked.

Here is my code:
function plotMyImages(handles, data, depth, Score, flag)
if flag
h1 = handles.axes1_1;
h2 = handles.axes1_2;
else
h1 = handles.axes2_1;
h2 = handles.axes2_2;
end
cla(h1, 'reset');
im1 = imagesc(h1, 'CData', data, 'YData', depth);
set(h1, 'YDir', 'reverse'); box(h1, 'on');
xlabel(h1, 'Distance');
ylabel(h1, 'Depth') ;
cla(h2, 'reset');
im2 = plot(h2, Score, '*');
xlabel(h2, 'Distance');
appel = @show_in_figure;
set(im1, 'ButtonDownFcn', appel(flag)); % ButtonDownFcn modified to show figure on the larger axes
set(im2, 'ButtonDownFcn', appel(flag)); % ButtonDownFcn modified to show figure on the larger axes
The show_in_figure() is as follows:
function show_in_figure(hObject, event, handles, flag)
hfig = findobj('Type', 'axes', 'Tag', 'axes_large1');
copyobj(hObject, hfig);
xx = get(gca, 'XLim'); yy = get(gca, 'YLim');
set(hfig, 'XLim', xx);
set(hfig, 'YLim', yy);
xlabel(hfig, 'Distance');
ylabel(hfig, 'Depth');
hfig1 = findobj('Type', 'axes', 'Tag', 'axes_large2');
if flag
h1 = handles.axes1_2;
else
h1 = handles.axes2_2;
end
copyobj(h1, hfig1);
xlabel(hfig1, 'Distance');
Is there anything that I'm doing wrong here? I am using MATLAB 2018a.
Accepted Answer
More Answers (0)
Categories
Find more on Migrate GUIDE Apps 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!