How to eliminate "Edit Plot" arrow error in a copied figure?

2 views (last 30 days)
I have a set of figures that I copy then delete using the code from this question, which I've reproduced below. However, when I use the "Edit Plot" arrow on the figure toolbar of one of the new figures, I get the following errors, after which I can use the Edit Plot arrow with no error. What code revision will allow the Edit Plot arrow to work the first time in the copied figure? In case it is related, a very long menu is generated in the copied figure window, in which "File, Edit, View,..." appears several (4) times.
Error using findall (line 24) Invalid handles passed to findall.
Error in plotedit>update_edit_menu (line 363) cut = findall(kids,'flat','Tag','figMenuEditCut');
Error in plotedit>localModeStartFcn (line 298) update_edit_menu(fig, false);
Error in hgfeval (line 63) feval(fcn{1},varargin{:},fcn{2:end});
Error in uitools.uimode/modeControl (line 14) hgfeval(hThis.ModeStartFcn);
Error in uitools.uimodemanager/schema>localSetMode (line 108) set(newMode,'Enable','on');
Error in activateuimode (line 27) set(hManager,'CurrentMode',hMode);
Error in plotedit (line 169) activateuimode(fig,'Standard.EditPlot');
27 set(hManager,'CurrentMode',hMode);
Code I want to revise to eliminate error messages from Edit Plot arrow:
% Get a list of all existing figures
figList = sort(get(0,'Children'));
for iOld = 1:length(figList)
figOld = figList(iOld); % This is a figure to replace
% Used later to make sure size of figure is correct
posOld = get(figOld, 'pos');
figNew = figure; % Make new figure
% Used later to make figure appear at
% default horizontal position on screen
posNew = get(figNew, 'pos');
% Copy over lines (but not formatting)
copyobj(allchild(figList(iOld)),figNew);
% Reproduce figure name and size however don't move it horizontally
set(figNew, 'Name', get(figOld, 'Name'), ...
'pos', [posNew(1:2) posOld(3:4)]);
% Get rid of old figure
close(figList(iOld));
end

Accepted Answer

José-Luis
José-Luis on 10 Jun 2014
Edited: José-Luis on 10 Jun 2014
When you do allchild(figList(iOld)), you are copying everything. That includes the uicontrols and menu. That is the source of the error. If you only want to copy the graphics objects, you could do as follows (will copy only the 'axes' objects):
for ii = 1:10
plot(rand(10,1));
end
% Get a list of all existing figures
figList = sort(get(0,'Children'));
for iOld = 1:length(figList)
figOld = figList(iOld); % This is a figure to replace
% Used later to make sure size of figure is correct
posOld = get(figOld, 'pos');
figNew = figure; % Make new figure
% Used later to make figure appear at
% default horizontal position on screen
posNew = get(figNew, 'pos');
% Copy over lines (but not formatting)
%Copy only the axes %This is the new bit
kids = allchild(figList(iOld));
type = get(kids,'Type');
idx = strcmp(type,'axes');
copyobj(kids(idx),figNew);
% Reproduce figure name and size however don't move it horizontally
set(figNew, 'Name', get(figOld, 'Name'), ...
'pos', [posNew(1:2) posOld(3:4)]);
% Get rid of old figure
close(figList(iOld));
end

More Answers (0)

Categories

Find more on Graphics Object Properties 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!