To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016
How can I take the code below to just copy the graphic on axes component (axes1) to clipboard. I then have code to paste it to excel. It currently copies all of my matlab screen.
axes(handles.axes1) Z=peaks surf(Z) print -dmeta; %.................Copying to clipboard
No products are associated with this question.
You could use Yair Altman's screencapture utility from the FEX: http://www.mathworks.com/matlabcentral/fileexchange/24323-screencapture-get-a-screen-capture-of-a-figure-frame-or-component
screencapture('handle',ax, 'filename', fn); % save the graph in file fn exlSheet.Shapes.AddPicture(fn,0,1,... 20,... % distance from left of sheet 20,... % distance from top of sheet 600,... % width 400); % height
Note that you will need to have opened an actxserver connection to MATLAB. In the above, ax is the handle to your axes, fn is the file where your image is saved, and exlSheet is an Excel Sheet object.
EDIT: Here is some sample actxserve code. I have had a chance to test this and it works for me. Refer to http://www.mathworks.com/help/techdoc/ref/actxserver.html if needed.
x = 0:0.1:10; y = sin(x); f = figure; ax = axes('parent',f); plot(ax,x,y);
fn = fullfile(pwd,'myplot.bmp'); screencapture('handle',ax, 'filename', fn);
e = actxserver('Excel.application'); eW = e.Workbooks; eF = eW.Add; % start a new file; use Open method for existing files eS = eF.ActiveSheet; e.Visible = 1; % Excel window won't show up by default eS.Shapes.AddPicture(fn,0,1,... 20,... % distance from left of sheet 20,... % distance from top of sheet 400,... % width 300); % height