gca
If the axis you are currently interacting with is the one you want to modify just issue the command:
TightAxis(FIGURENAME)
Where FIGURENAME is a string that will be used to label the figure window.
Here is the function:
function TightAxis(title)
%First create an axis if
%the user doesn't have a gca
%and get the handle
haxis=gca;
%Best Image Fit Algorithm
set(gcf,'Visible','off')
set(haxis,'Position',[0,0,1,1])
monitorRes=get(0,'ScreenSize');
imageSize=get(haxis,'PlotBoxAspectRatio');
pos=get(gcf,'Position');
%Check for over sized images
%IF the native resolution of
%the image fits in the screen resolution
%AND the image does not contain a
%1-pixel dimension
%THEN scale the image to be displayed
%at 1x Resolution
if (imageSize(1)<=monitorRes(3)
&& imageSize(1)>1
&& imageSize(2)<=monitorRes(4)
&& imageSize(1)>1)
set(gcf,'Position',[0,0,imageSize(1:2)])
else
set(gcf,'Position',[0,0,pos(3:4)])
end
set(gcf,'Name',title,'NumberTitle','off')
set(gcf,'MenuBar','none')
zoom on;
movegui(gcf,'center')
set(gcf,'Visible','on')
Sweet function. Was this from DIP?
ReplyDeleteYep, it has been one of my most used functions
ReplyDelete