As DMR sais, it's necesary to set the 'CurrentAxes'. For example, if you want to plot into the axis with the tag name 'axis1' you should simply add:
axes(handles.axes1);
to your code. Below is a very simple example for a figure containing a 'axis1' and 'axis2' using your code (corrected) code from above. Im not really shure wether you want to plot on an axis on your gui itself or a separate figure. I hope I covered both cases.
function varargout = Test(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Test_OpeningFcn, ...
'gui_OutputFcn', @Test_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Test is made visible.
function Test_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for Test
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
plot(handles.axes2,-2*pi:0.1:2*pi,sin(-2*pi:0.1:2*pi));
% Initialize and clear plot window
MyVariable = ones(11,6);
MyVariable(1:5,1) = 0;
axes(handles.axes1);
for x = 1:11
for y = 1:6
if (MyVariable(x,y) == 1)
rectangle('position', [x-1, y-1, 1, 1] ,'EdgeColor', 'w', 'facecolor', 'k');
elseif(MyVariable(x,y) == 0)
rectangle('position', [x-1, y-1, 1, 1], 'facecolor', 'w');
end
end
end
title('West Wall Array',...
'FontWeight','bold')
figure(2); clf;
for x = 1:11
for y = 1:6
if (MyVariable(x,y) == 1)
rectangle('position', [x-1, y-1, 1, 1] ,'EdgeColor', 'w', 'facecolor', 'k');
elseif(MyVariable(x,y) == 0)
rectangle('position', [x-1, y-1, 1, 1], 'facecolor', 'w');
end
end
end
title('West Wall Array',...
'FontWeight','bold')
function varargout = Test_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
Your guide GUI should look like this:
And your result like this: