From: Joe Volzer on
I have just started learning how to write GUIs in MATLAB. I am trying to write a context menu that copies a single subplot to a new figure.

I was able to get a test case working by using the following code:
close all
clear

figure
s = NaN(2,1);
p = NaN(2,1);
t = 0:.1:2*pi;


s(1)=subplot(2,1,1);
hold on; k= plot(t,sin(t));
plot(t,rand(length(t),1).*sin(t)','r');
hold off;

s(2)=subplot(2,1,2);
hold on;
plot(t,cos(t));plot(t,zeros(length(t),1),'k--');
hold off;


plots=2;
% build context menu specific to each subplot
for i = 1:plots
hcmenu = uicontextmenu;
hcb = ['figure, axes, copyobj(allchild(s(',num2str(i),')),gca);'];
item = uimenu(hcmenu, 'Label', 'Embiggen', 'Callback', hcb);
set(s(i),'uicontextmenu',hcmenu);
end



Here is the current version of my code:
for j = 1:pages
for k = 1:5

....

% This portion generates the subplots

....

% This loop builds and attaches a context menu to each subplot.
for plots=1:3
% We use count-4+plots as an index instead of count. This is so
% context menus can be attached to the appropriate plots.

hcmenu = uicontextmenu;

% This builds the callback for the context menu
figh = ['hsp(',num2str(count-4+plots),')'];
hcb = ['figure,axes,copyobj(allchild(', figh ,'),gca);'];
item = uimenu(hcmenu, 'Label', 'Embiggen', 'Callback', hcb);
set(hsp(count-4+plots),'uicontextmenu',hcmenu);
end

end
end



hsp is an array that contains the handles of my subplots. It is initialized as an array of zeros. When I right click on the desired subplot, the context menu appears. When I try to "Embiggen" the subplot, I get the following error:
??? Error using ==> waitfor
Undefined function or method 'hsp' for input arguments of type 'double'.

??? Error using ==> waitfor
Error while evaluating uimenu Callback

Any suggestions as to what might work? Thanks in advance.
From: Joe Volzer on
This thread contained the information that I was looking for: http://www.mathworks.ch/matlabcentral/newsreader/view_thread/120986
 | 
Pages: 1
Prev: mxGetPr size as double*
Next: plot as a gif