How can I convert the size of the figure or UI control in characters to pixels in MATLAB 7.8 (R2009a)?

5 views (last 30 days)
I would like to set the size of the figure or UI control in characters relative to the screen size, which is given in pixels. The default Units of the figure and UI controls are 'characters'. Presently I am first changing the Units to 'pixels', set the size in pixels and set the Units back to 'characters'. I would like to know if there is a way to find out what is the size of a figure in characters given the size in pixels.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 20 Jul 2009
To calculate the conversion factor from pixels to characters, create an empty figure, which has 'pixels' as its default 'units', get its size in pixels, set the units to 'characters' and get its size in characters. Divide the size of the figure in pixels by the size of the figure in characters to get the conversion factor:
figure
size_pixels=get(gcf,'Position');
set(gcf,'Units','characters')
size_characters=get(gcf,'Position');
f=size_pixels(3:4)./size_characters(3:4)
Given a size in pixels
a=[width height]
divide by f to get the size in characters:
a_characters=a./f

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!