MultiPlotXY - Plot two columns of each input matrix against each other. Plot the second column of each input matrix as a function of the first column. Optionally, alternative pairs of columns can be plotted against each other. USAGE p = MultiPlotXY(X,columns,Y,columns,...,<options>) X the first data to plot columns optional pair of columns to plot Y the second data to plot columns optional pair of columns to plot ... additional data and column indices <options> options for function <a href="matlab:help plot">plot</a>
0001 function p = MultiPlotXY(varargin) 0002 0003 %MultiPlotXY - Plot two columns of each input matrix against each other. 0004 % 0005 % Plot the second column of each input matrix as a function of the first column. 0006 % Optionally, alternative pairs of columns can be plotted against each other. 0007 % 0008 % USAGE 0009 % 0010 % p = MultiPlotXY(X,columns,Y,columns,...,<options>) 0011 % 0012 % X the first data to plot 0013 % columns optional pair of columns to plot 0014 % Y the second data to plot 0015 % columns optional pair of columns to plot 0016 % ... additional data and column indices 0017 % <options> options for function <a href="matlab:help plot">plot</a> 0018 % 0019 0020 % Copyright (C) 2004-2011 by Michaƫl Zugaro 0021 % 0022 % This program is free software; you can redistribute it and/or modify 0023 % it under the terms of the GNU General Public License as published by 0024 % the Free Software Foundation; either version 3 of the License, or 0025 % (at your option) any later version. 0026 0027 if nargin < 1, 0028 error('Incorrect number of parameters (type ''help <a href="matlab:help MultiPlotXY">MultiPlotXY</a>'' for details).'); 0029 end 0030 0031 % We need to parse the parameters twice: 0032 % 1) Count number of data matrices, because we need to know the number of subplots before we start plotting 0033 n = DoIt(0,varargin{:}); 0034 % 2) Plot 0035 DoIt(n,varargin{:}); 0036 0037 function nData = DoIt(nSubplots,varargin) 0038 0039 nData = 0; 0040 n = length(varargin); 0041 % Parse parameters 0042 % i loops through parameters 0043 % j points to the first candidate parameter to be passed to 'plot' 0044 % k points to the last parameter to be passed to 'plot' 0045 i = 1; 0046 while i <= n, 0047 % The first parameter is the data to plot 0048 X = varargin{i}; 0049 % Default columns 0050 columns = [1 2]; 0051 % Parse additional parameters if any 0052 if i >= n, 0053 j = 0;k = 0; % dummy values 0054 else 0055 % Is the second parameter a list of columns? 0056 if isivector(varargin{i+1},'#2','>0'), 0057 columns = varargin{i+1}; 0058 j = i + 2; 0059 else 0060 j = i + 1; 0061 end 0062 % Parse additional parameters if any 0063 k = j-1; 0064 if j <= n, 0065 for k = j:n, 0066 % Is the next parameter an option for 'plot'? 0067 % To answer this question, we use the following heuristics: 0068 % If the next parameter is a matrix, it is *not* an option for plot, but the next data to plot, 0069 % because plot does not take matrices as options - except for one possible exception: following 0070 % the property 'UserData'. 0071 if isdmatrix(varargin{k}), 0072 if ~ischar(varargin{k-1}) | ~strcmp(lower(varargin{k-1}),'userdata'), 0073 % This parameter is a matrix and does not follow 'UserData': it is the next data to plot 0074 k = k - 1; 0075 break 0076 end 0077 end 0078 end 0079 end 0080 end 0081 nData = nData+1; 0082 if nSubplots ~= 0, 0083 subplot(nSubplots,1,nData); 0084 if j > i && k >= j, 0085 PlotXY(X,columns,varargin{j:k}); 0086 else 0087 PlotXY(X,columns); 0088 end 0089 end 0090 i = max([i k]) + 1; 0091 end