Subplot disappeared after getting its handle
Show older comments
I have a figure consisting of five subplots and I want to save or open one of them in another figure. For some reason, whenever I tried to get the handle with the first line. That subplot specifically just turned empty and the new figure contains only an empty axis too. Any help on selecting a subplot would be appreciated.
h_subplot = subplot(5,1,2);
figure;
h_newaxis = copyobj(h_subplot, gcf);
set(h_newaxis, 'Position', get(0,'DefaultAxesPosition'));
Accepted Answer
More Answers (1)
Constantino Carlos Reyes-Aldasoro
on 6 May 2023
The problem is the order in which you are passing the commands, you create a subplot in a figure, then you call for a new figure and then you use gcf. Try like this
h_fig = figure;
h_subplot = subplot(5,1,2);
h_newaxis = copyobj(h_subplot, h_fig);
set(h_newaxis, 'Position', get(0,'DefaultAxesPosition'));
1 Comment
Shao-Yu Wang
on 6 May 2023
Categories
Find more on Subplots 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!

