No BSD License  

Highlights from
cropplot

from cropplot by Joacim Rådstam
Remove invisible data from the plot to minimize file size when saved.

cropplot(varargin)
function cropplot(varargin)
% Remove invisible data from the plot to minimize file size when saved.
%
% When a 2D-plot is zoomed the cropplot function crops the invisible data
% to the x-axis limits keeping all y-axis data within these limits.
%
% For large data series that are zoomed in, cropplot will reduce the file
% size when the figure is saved to disc.
%
% Syntax: cropplot
%         cropplot(figurehandles)
%
% Input:  figurehandles - (optional) vector of figure handles for two
%                         dimensional plots to be cropped.
%
% Output: Cropped plots.
%
% Created by:  Joacim Rdstam, Sweden
% Email:       jocke@elektroteknik.net

% Requirements:  Matlab
%
% Notes: 
%
% Revision date   By                Comment
% 2006-07-07      Joacim Rdstam    First version.

if nargin<1
    fig = gcf;
elseif nargin==1
    fig = varargin{1};
else
    error(sprintf('Only one input argument allowed.\nTo use cropplot on more than one figure, put all figure handles in a vector.'))
end

for f=1:length(fig)
   haxes = findobj(fig(f), 'Type', 'axes', '-and', 'Tag', '');
   for n=1:length(haxes)
      xl = get(haxes(n),'XLim');
      lines = findobj(haxes(n), 'Type', 'line');
      for m=1:length(lines)
         xdata = get(lines(m), 'XData');
         ydata = get(lines(m), 'YData');
         I = find(xdata <= xl(2));
         I = find(xdata(I) >= xl(1));
         set(lines(m), 'XData', xdata(I))
         set(lines(m), 'YData', ydata(I))
      end
   end
end

Contact us at files@mathworks.com