diff --git a/matlab/figureFullScreen.m b/matlab/figureFullScreen.m new file mode 100644 index 0000000..f199634 --- /dev/null +++ b/matlab/figureFullScreen.m @@ -0,0 +1,67 @@ +function handle = figureFullScreen(varargin) +%FIGUREFULLSCREEN Open a figure with specific dimensions + + % Handle inputs + p = inputParser(); + p.addOptional('width', []); + p.addOptional('height', []); + p.addOptional('left', []); + p.addOptional('bottom', []); + p.addParamValue('units', '', @ischar); + p.parse(varargin{:}); + p = p.Results; + + % Compute dimensions + if isempty(p.width) && isempty(p.height) + p.width = 1; + p.height = 1; + elseif ~isempty(p.width) && isempty(p.height) + switch numel(p.width) + case 1 + p.height = p.width; + case 2 + p.height = p.width(2); + p.width = p.width(1); + case 3 + p.height = p.width(2); + p.left = p.width(3); + p.width = p.width(1); + case 4 + p.height = p.width(2); + p.left = p.width(3); + p.bottom = p.width(4); + p.width = p.width(1); + end + end + + % Automagically set the units + if isempty(p.units) + if any([p.width p.height p.left p.bottom] > 1) + p.units = 'pixels'; + else + p.units = 'normalized'; + end + end + + % Determine reference to compute left and/or bottom + units_original = get(0, 'Units'); + set(0, 'Units', p.units); + ref = get(0, 'Screensize'); + + % Reset the units + set(0, 'Units', units_original); + + % Compute left and/or bottom + if isempty(p.left) + p.left = 0; + p.left = (ref(3) - p.width) / 2; + end + if isempty(p.bottom) + p.bottom = 0; + p.bottom = (ref(4) - p.height) / 2; + end + + % Make the new figure + handle = figure('units', p.units, 'outerposition', [p.left p.bottom p.width p.height]); + +end