Programmatic equivalent of 'copy figure' menu action
-
21-12-2019 - |
Question
I am developing a Matlab GUI application that plots a figure with additional UI elements in the GUI window. I would like to add a menu action to the GUI window menu that exactly duplicates the standard figure window menu's "Edit|Copy Figure" entry, so that the copy figure options 'preserve information', 'force white background', and 'match figure screen size' can be applied.
Does anyone know how to do this?
Thanks!
EDIT To add what worked
Rather than trying to copy/modify/paste the code in the figure window menu handler, I just called it from the GUI menu function
% --------------------------------------------------------------------
function CopyFigureMenuItem_Callback(hObject, eventdata, handles)
% hObject handle to CopyFigureMenuItem (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
editmenufcn(handles.figure1, 'EditCopyFigure');
Almost certainly not future-proof, and not guaranteed to work in any future version, but in R2014a it does what I want!
Solution
Type
>>edit editmenufcn
at Matlab command prompt to see all the programmatic invocations of the Edit Menu. Apparently what you are looking for is:
editmenufcn(hFigure, 'EditCopyFigure');
Of course, hFigure
should be the handle of the figure that you want copied.
Later edit
Peeking into the code might give you hints to implement more refined functionalities. The body of the function is a huge switch
statement; looking for 'EditCopyFigure'
string will give you the code snippet that you're interested in. Be careful not to modify this function, or to save changes, though. :-)
However, this function is undocumented and might be changed/removed in later versions. I hope you are not bothered by this.
Even later edit
Apparently the above is not the answer to the question. The answer would be "Yes, there is at least one who knows how to do this." :-)