0001 function a = PiecewiseLinearAxis(x,axis,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 if nargin < 1,
0022 error('Incorrect number of parameters (type ''help <a href="matlab:help PiecewiseLinearAxis">PiecewiseLinearAxis</a>'' for details).');
0023 end
0024
0025
0026 if ~isdvector(x,'<'),
0027 error('Incorrect values (type ''help <a href="matlab:help PiecewiseLinearAxis">PiecewiseLinearAxis</a>'' for details).');
0028 end
0029 if nargin < 2,
0030 axis = 'x';
0031 else
0032 axis = lower(axis);
0033 end
0034 if ~isastring(axis,'x','y'),
0035 varargin = {axis,varargin{:}};
0036 axis = 'x';
0037 end
0038 if isempty(varargin)
0039 varargin = {'k:'};
0040 end
0041
0042
0043 dx = diff(x);
0044 binSize = median(dx);
0045 gaps = [find(dx>2*binSize)+1];
0046 a = gca;
0047 set(a,[axis 'lim'],[min(x)-binSize/2 max(x)+binSize/2]);
0048 if isempty(gaps), return; end
0049
0050
0051
0052 X = linspace(x(1),x(end),length(x))';
0053
0054
0055 if strcmp(axis,'x'),
0056 PlotHVLines(X(gaps),varargin{:});
0057 else
0058 PlotHVLines(X(gaps),'h',varargin{:});
0059 end
0060
0061
0062
0063
0064
0065 P = get(a,'position');
0066 gaps = [1;gaps;length(x)];
0067 ticks = [];
0068 tickLabels = [];
0069 for i = 2:length(gaps),
0070
0071 start = X(gaps(i-1));
0072 stop = X(gaps(i));
0073
0074
0075 if strcmp(axis,'x'),
0076 factor = P(3)/(x(end)-x(1))
0077 p = [0 0.25 (stop-start)*factor 0.5];
0078 else
0079 factor = P(4)/(x(end)-x(1));
0080 p = [0.25 0 0.5 (stop-start)*factor];
0081 end
0082 tmp = axes('position',p,'visible','off');
0083
0084 set(tmp,[axis 'lim'],[x(gaps(i-1)) x(gaps(i)-1)]);
0085
0086 l = str2num(get(tmp,[axis 'ticklabel']));
0087
0088 t = interp1(x,X,l);
0089
0090 tickLabels = [tickLabels;l];
0091 ticks = [ticks;t];
0092 delete(tmp);
0093 end
0094
0095 set(a,[axis 'tick'],ticks,[axis 'TickLabel'],tickLabels);