I create a figure and a panel of uicontrols. When I run the program, the panel overlays the default axes( or plot area if that is more appropriate). So, I want to have the panel at a certain position and the axes( or plot area) set at a separate position. I've read Matlab help and tried many variations of set, get, CurrentAxes, axis methods. Still I can't figure out. The basic code until now, is
mytitle = 'Kinematic Control of a Redudant Robotic System';
simfig = figure( 'menubar', 'none', 'position', [ 140 140 600 600], 'Name', mytitle, 'NumberTitle', 'off');
ax = axes( 'Parent', simfig, 'Units', pixels, 'Position', [ 150 150 300 300], 'XLim', [ 0 10], 'YLim', [ 0 8]);
panbut = uipanel( simfig, 'Units', pixels, 'position', [20 45 143 150], 'Title', 'Simulation Buttons');
%buttons
up = uicontrol( panbut, 'style', 'pushbutton', 'string', 'up', 'position', [ 50 90 40 40], 'callback', @up_button_press);
down = uicontrol( panbut, 'style', 'pushbutton', 'string', 'down', 'position', [ 50 10 40 40], 'callback', @down_button_press);
right = uicontrol( panbut, 'style', 'pushbutton', 'string', 'right','position', [ 90 50 40 40], 'callback', @right_button_press);
left = uicontrol( panbut, 'style', 'pushbutton', 'string', 'left', 'position', [ 10 50 40 40], 'callback', @left_button_press);
What do I miss?
If you position your plots using the position
property, results can be quite inaccurate, because the space for labels and ticklabels add to the space you define in position
.
In order to avoid overlap you can set the OuterPosition
property of the axes
:
mytitle = 'Kinematic Control of a Redudant Robotic System';
simfig = figure( 'menubar', 'none', 'position', [ 140 140 600 600],...
'Name', mytitle, 'NumberTitle', 'off');
ax = axes( 'Parent', simfig, 'Units', 'pixels','outerPosition', [ 150 150 300 300], ...
'XLim', [ 0 10], 'YLim', [ 0 8]);
panbut = uipanel( simfig, 'Units', 'pixels', 'position',...
[20 45 143 150], 'Title', 'Simulation Buttons');
%buttons
up = uicontrol( panbut, 'style', 'pushbutton',...
'string', 'up', 'position', [ 50 90 40 40],...
'callback', @up_button_press);
down = uicontrol( panbut, 'style', 'pushbutton',...
'string', 'down', 'position', [ 50 10 40 40], ...
'callback', @down_button_press);
right = uicontrol( panbut, 'style', 'pushbutton',...
'string', 'right','position', [ 90 50 40 40], ...
'callback', @right_button_press);
left = uicontrol( panbut, 'style', 'pushbutton',...
'string', 'left', 'position', [ 10 50 40 40],...
'callback', @left_button_press);