Values NaN( N ot a N ) can be an unpleasant thing, but also convenient in this case.
, Matlab , (NaN). , , NaN Matlab , . Matlab , NaN.
, , 3 , , :
%% // sample data sets
yf = @(x) 2*x+40+randi(7,size(x)) ;
x1 = 57:61 ; y1 = yf(x1) ;
x2 = 72:76 ; y2 = yf(x2) ;
x3 = 80:83 ; y3 = yf(x3) ;
, Y. , . struture , cellfun . cellfun.
,
%% // have to group the data sets in a cell array or structure to implement global operations
xc = { x1 ; x2 ; x3 } ;
yc = { y1 ; y2 ; y3 } ;
:
%
maxVal = cellfun(@max,yc) ;
minVal = cellfun(@min,yc) ;
maxYspan = max( maxVal-minVal ) ;
totalSpan = max(maxVal)-min(minVal) ;
%
%
yBreakIncrement = round( totalSpan / 10 ) ; %
yTickIncrement = round( maxYspan /5 ) ; %
%%
%
setSubstract = [0 ; cumsum( (minVal(2:end)-maxVal(1:end-1))- yBreakIncrement ) ] ;
%
Yall = cellfun(@minus , yc , num2cell(setSubstract) , 'uni',0) ;
%
Yall = cellfun( @(a,b) cat(2,a,b) , Yall , repmat({NaN},length(yc),1) , 'uni',0) ;
Yall = cat( 2, Yall{:} ) ;
%
Yall(end) = [] ;
%%
%
Y_tickpos = cellfun(@colon, num2cell(minVal), repmat({yTickIncrement},length(yc),1) , num2cell(maxVal) , 'uni',0) ;
%
Y_labels = cellstr( num2str( cat(2, Y_tickpos{:} ).') ) ; %'
%
Y_tickpos = cellfun(@minus , Y_tickpos , num2cell(setSubstract) , 'uni',0) ;
Y_tickpos = cat( 2, Y_tickpos{:} ) ;
%%
%
X = 1:length(Yall) ;
X_labels = cellstr( num2str( cat(2, xc{:} ).') ) ; %'
X_tickpos = X(~isnan(Yall)) ; %
%%
plot(X,Yall) %
%
set(gca, 'XTick' , X_tickpos , 'XTickLabel' , X_labels )
set(gca, 'YTick' , Y_tickpos , 'YTickLabel' , Y_labels )
- :

, . .