From 5515a8a64afe35f3ea498d34d3e3ac92deb6eda7 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 24 Jul 2013 10:40:01 -0400 Subject: [PATCH] reporting: @series: add zerotol option --- doc/dynare.texi | 7 ++++++- matlab/reports/@series/getLine.m | 17 +++++++++++++++-- matlab/reports/@series/series.m | 2 ++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index f16cf8736..6ebe67ba0 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -8359,7 +8359,7 @@ Whether or not to show vertical lines separating the columns. Default: @code{fal @end defmethod @anchor{addSeries} -@defmethod Report addSeries data, graphLineColor, graphLineStyle, graphLineWidth, graphMarker, graphMarkerEdgeColor, graphMarkerFaceColor, graphMarkerSize, tableShowMarkers, tableAlignRight, tableNegColor, tablePosColor +@defmethod Report addSeries data, graphLineColor, graphLineStyle, graphLineWidth, graphMarker, graphMarkerEdgeColor, graphMarkerFaceColor, graphMarkerSize, tableShowMarkers, tableAlignRight, tableNegColor, tablePosColor, zerotol Adds a @code{Series} to a @code{Graph} or a @code{Table}. @optionshead @table @code @@ -8413,6 +8413,11 @@ zero. Default: @code{`red'} The color to use when marking Table data that is greater than zero. Default: @code{`blue'} +@item zerotol, @code{DOUBLE} +The zero tolerance. Anything smaller than @code{zerotol} and larger +than @code{-zerotol} will be set to zero before being +graphed. Default: @math{1e-6} + @end table @end defmethod diff --git a/matlab/reports/@series/getLine.m b/matlab/reports/@series/getLine.m index c1f61c61c..829bf8222 100644 --- a/matlab/reports/@series/getLine.m +++ b/matlab/reports/@series/getLine.m @@ -60,6 +60,9 @@ assert(~(strcmp(o.graphLineStyle, 'none') && isempty(o.graphMarker)), ['@series. % Validate xrange assert(isempty(xrange) || isa(xrange, 'dynDates')); +% Zero tolerance +assert(isfloat(o.zerotol), '@series.write: zerotol must be a float'); + %% if isempty(xrange) || xrange == o.data.time ds = o.data; @@ -67,8 +70,18 @@ else ds = o.data(xrange); end -opt = {'XData', 1:length(ds.data)}; -opt = {opt{:}, 'YData', ds.data}; +% if graphing data that is within zerotol, set to zero, create series and +% get line: +thedata = ds.data; +stz = bsxfun(@and, ... + bsxfun(@lt, thedata, o.zerotol), ... + bsxfun(@gt, thedata, -o.zerotol)); +if any(stz) + thedata(stz) = 0; +end + +opt = {'XData', 1:length(thedata)}; +opt = {opt{:}, 'YData', thedata}; opt = {opt{:}, 'Color', o.graphLineColor}; opt = {opt{:}, 'LineStyle', o.graphLineStyle}; diff --git a/matlab/reports/@series/series.m b/matlab/reports/@series/series.m index cf6f2db9a..6493dced7 100644 --- a/matlab/reports/@series/series.m +++ b/matlab/reports/@series/series.m @@ -51,6 +51,8 @@ o.tableMarkerLimit = 1e-4; o.tableAlignRight = false; +o.zerotol = 1e-6; + if nargin == 1 assert(isa(varargin{1}, 'series'),['@series.series: with one arg you ' ... 'must pass a series object']);