How can I select an axis of a GUI figure by clicking on it in order to ploting it to a seperate figure outside of the GUI?

Hello, I have a GUI function with one axis. But depending on the value of a variable named ChannelNumbers, I plot 1 to 4 plots using subplot function. For example, if Channel number is 4, I use subplot(4,1,1 to 4) to plot 4 sets of data. If it is 2, I have two subplots (2,1,1) and (2,1,2)
The question is that I want to select among these subplots by clicking on each of them so that when I click on any of axes, the corresponding data would be plotted to a seperate figure outside of the GUI. How I can decide among axes by clicking on each of them?
Thank you in advance,

 Accepted Answer

Great Monday morning warmup question! +1
function OpenSubPlotInNewFigue
for ii = 1:4
%Create foru subplots with a button down function pointed at
%copy2Figure with random data.
subplot(4,1,ii,'ButtonDownFcn',@copy2NewFigure);
hold on
plot(rand(1,10));
end
end
function copy2NewFigure(src,~)
hFig = figure; %new figure
hAx = axes('Parent',hFig); %new axes
copyobj(get(src,'children'),hAx); %copy the children of the clicked axes to the new one
end
Save this and run it.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!