function theResult = sortplot(x, y, theBinSize, varargin) % sortplot -- Plot sorted chunks. % sortplot(x, y, theBinSize, varargin) plots y(x), but % with y first sorted into bins of theChunkSize (default % is one-tenth the length of x). Any additional arguments, % such as line-type, are passed intact to "plot". % sortplot(nData, binSize) demonstrates itself for nData, % using the binSize. nData defaults to 1000; binSize to % one-tenth of nData. % sortplot('demo') demonstrates itself. % sortplot (no argument) demonstrates itself. % Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. % All Rights Reserved. % Disclosure without explicit written consent from the % copyright owner does not constitute publication. % Version of 14-May-1998 16:28:43. % Updated 18-Oct-1999 09:54:08. if nargin < 1 | isequal(x, 'demo'), x = 1000; end if nargin > 0 & ischar(x) & ~isequal(x, 'demo') x = eval(x); end if nargin > 1 & ischar(y) y = eval(y); end if length(x) == 1 help(mfilename) n = x; c = round(n./10); if nargin > 1, c = y(1); end x = 1:n; y = randn(1, n); subplot(2, 1, 1) plot(x, y) xlabel('X'), ylabel('Y') title(['Y = RandN( 1, ' int2str(n) ' )']) subplot(2, 1, 2) sortplot(x, y, c) xlabel('X'), ylabel('Sorted Y') title(['SortPlot( Y, ', int2str(c) ' )']) set(gcf, 'Name', 'SortPlot Demo') figure(gcf) zoomsafe all, findpt return end if nargin < 2 y = x(:); x = 1:length(y); theBinSize = ceil(length(x) ./ 10); varargin = {}; elseif nargin < 3 if ischar(y) varargin = {y}; y = x(:); x = 1:length(y); theBinSize = ceil(length(x) ./ 10); elseif length(y) == 1 theBinSize = y; y = x(:); x = 1:length(y); else theBinSize = ceil(length(x) ./ 10); varargin = {}; end elseif ischar(theBinSize) varargin = [varargin {theBinSize}]; theBinSize = upper(length(x) ./ 10); end x = x(:); y = y(:); [m, n] = size(x); width = ceil((length(y)) ./ theBinSize); u = zeros(theBinSize, width) + NaN; u(1:length(y)) = y; s = sort(u); s = s(:); s = s(1:length(y)); result = plot(x, s, varargin{:}); if nargout > 0, theResult = result; end