Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab UIControl Units

I am using uicontrol to create GUI Elements. Following is my Code

uicontrol('Style','pushbutton', 'String','Load data','Parent',hTabs(1),'Position',[250 825 80 20], 'Callback',@ButtonCallback);

Here the problem is when i am using Units normalized option the GUI element is disappearing from Screen. I want to use normalized so that GUI adjusts itself in different screen resolutions. Any idea on this would be very helpful for me.

like image 384
Satya Vamsi Avatar asked May 26 '26 02:05

Satya Vamsi


2 Answers

When you use Normalized units you need to define the position between 0 and 1, with 0 being the bottom/left hand side and 1 being the total height/width of the containing object.

You are currently defining the position using numbers that are well out of this range. You can do two things.

  • Switch the units to normalized in seperate function call (demonstrated below)
  • Create the uicontrol with normalized units, but you'll have to calculate the proper position vector

Here are examples on how to do either

A simple solution is to create the uicontrol and then set the units to normalized in a separate call

u = uicontrol(...) %don't specify the units
set(u,'Units', 'Normalized'); % this solves your problem

If you want to get the position vector in normalized units

normPos = get(u, 'Position') % get the position in normal space

Then use these numbers to create the uicontrol with normalized units:

u = uicontrol(...,'Units','Normalized', 'Position', normPos); 
like image 176
slayton Avatar answered May 27 '26 19:05

slayton


When using the 'units','normalized' option you must change your position vector. The figure reference system has coordinates between 0 and 1.

E.g.

uicontrol('Style','pushbutton',...
          'String','Load data',...
          'Parent',hTabs(1),...
          'units','normalized',...
          'Position',[0 0 0.1 0.1],...
          'Callback',@ButtonCallback); 

gives you a button 10% of the height and width in the lower left corner of the parent panel.

like image 36
Not Bo Styf Avatar answered May 27 '26 20:05

Not Bo Styf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!