jwm
jwm

Reputation: 5040

Maltab: copy axes in a gui to a figure

I am going to save an image in the GUI to a sperate figure. Some of codes relevant are as follows:

axes(handles.axes1); %axes object
subplot(131); imshow(tempData(:,:,1),[]); title('I1');
subplot(132); imshow(tempData(:,:,2),[]); title('I2');
subplot(133); imshow(tempData(:,:,3),[]); title('I3');
%The three images are displayed in the GUI

% saved to a new figure
handles.axes1
figurenew = figure;
copyobj(handles.axes1,figurenew);

Then, there is an error when running the code:

Error using copyobj
Copyobj cannot create a copy of an invalid handle.

Does that means the handle handle.axes1 no longer exist? Then how to modify the codes to save the displayed image in the GUI?

Upvotes: 0

Views: 82

Answers (1)

oro777
oro777

Reputation: 1110

Each subplot has its own Axes object. You can get this Axes object by writing as follow.

figure;
axes1 = subplot(131);

Then you can copy the object as you wrote.

figurenew = figure;
copyobj( axes1, figurenew );

Upvotes: 2

Related Questions