1function h = plot(o, varargin) 2 3% Overloads Matlab/Octave's plot function for dseries objects. 4 5% Copyright (C) 2013-2017 Dynare Team 6% 7% This file is part of Dynare. 8% 9% Dynare is free software: you can redistribute it and/or modify 10% it under the terms of the GNU General Public License as published by 11% the Free Software Foundation, either version 3 of the License, or 12% (at your option) any later version. 13% 14% Dynare is distributed in the hope that it will be useful, 15% but WITHOUT ANY WARRANTY; without even the implied warranty of 16% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17% GNU General Public License for more details. 18% 19% You should have received a copy of the GNU General Public License 20% along with Dynare. If not, see <http://www.gnu.org/licenses/>. 21 22% Get the number of dseries objects 23if isequal(nargin,1) 24 ndseries = 1; 25 nvariables = vobs(o); 26else 27 if isdseries(varargin{1}) 28 ndseries = 2; 29 nvariables = vobs(o); 30 nobservations = nobs(o); 31 if nargin>2 && any(cellfun(@isdseries,varargin(2:end))) 32 error('dseries::plot: You cannot pass more two dseries objects!') 33 end 34 if ~isequal(nvariables, vobs(varargin{1})) 35 error('dseries::plot: The two dseries objects must have the same number of variables!') 36 end 37 if ~isequal(nobservations, nobs(varargin{1})) 38 error('dseries::plot: The two dseries objects must have the same number of observations!') 39 end 40 else 41 ndseries = 1; 42 nvariables = vobs(o); 43 end 44end 45 46switch ndseries 47 case 1 48 if isequal(nvariables,1) 49 hh = plot(o.data,varargin{:}); 50 else 51 if ~isempty(varargin) 52 message = sprintf('dseries::plot: dseries object %s has %d>1 variables but you passed additional arguments to the plot function.\n These additional arguments won''t ne interpreted. Use the Matlab/Octave set command and the plot\n handle instead if you wish to modify the properties of the plotted time series.',inputname(1),nvariables); 53 warning(message) 54 end 55 hh = plot(o.data); 56 end 57 axis tight; 58 id = get(gca,'XTick'); 59 if isequal(id(1),0) 60 dates = strings([o.dates(1)-1,o.dates(id(2:end))]); 61 else 62 ID = id(find(isint(id))); 63 set(gca,'XTick',ID); 64 dates = strings(o.dates(ID)); 65 end 66 set(gca,'XTickLabel',dates); 67 case 2 68 [o0, o1] = align(o, varargin{1}); 69 if isequal(nvariables,1) 70 hh = plot(o0.data, o1.data, varargin{2:end}); 71 else 72 if length(varargin)>1 73 message = sprintf('dseries::plot: dseries objects %s and %s have %d>1 variables but you passed additional arguments to the plot function.\n These additional arguments won''t ne interpreted. Use the Matlab/Octave set command and the plot\n handle instead if you wish to modify the properties of the plotted time series.',inputname(1),inputname(2),nvariables); 74 warning(message) 75 end 76 hh = plot(o0.data, o1.data); 77 end 78 otherwise 79 error('dseries::plot: This is a bug! Please report the bug to the authors of Dynare.') 80end 81 82if nargout 83 h = hh; 84end