From 0f61ae941ac6f8d2402accab0b29773bde8cf188 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 22 May 2014 19:01:48 +0200 Subject: [PATCH] reporting: make zerotol work for both graphs and reports --- matlab/reports/@report_series/printSeries.m | 2 +- .../@report_series/setDataToZeroFromZeroTol.m | 28 +++++++++++++++++++ .../@report_series/writeSeriesForGraph.m | 11 +------- 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 matlab/reports/@report_series/setDataToZeroFromZeroTol.m diff --git a/matlab/reports/@report_series/printSeries.m b/matlab/reports/@report_series/printSeries.m index 15867a068..e1a6f0b49 100644 --- a/matlab/reports/@report_series/printSeries.m +++ b/matlab/reports/@report_series/printSeries.m @@ -36,7 +36,7 @@ dataString = sprintf('%%.%df', precision); precision = 10^precision; data = dser(dates); -data = data.data; +data = setDataToZeroFromZeroTol(o, data); for i=1:size(data,1) fprintf(fid, '&'); if o.tableShowMarkers diff --git a/matlab/reports/@report_series/setDataToZeroFromZeroTol.m b/matlab/reports/@report_series/setDataToZeroFromZeroTol.m new file mode 100644 index 000000000..25daeb15f --- /dev/null +++ b/matlab/reports/@report_series/setDataToZeroFromZeroTol.m @@ -0,0 +1,28 @@ +function d = setDataToZeroFromZeroTol(o, ds) +%function d = setDataToZeroFromZeroTol(o, ds) + +% Copyright (C) 2014 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see . + +d = ds.data; +stz = bsxfun(@and, ... + bsxfun(@lt, d, o.zeroTol), ... + bsxfun(@gt, d, -o.zeroTol)); +if any(stz) + d(stz) = 0; +end +end \ No newline at end of file diff --git a/matlab/reports/@report_series/writeSeriesForGraph.m b/matlab/reports/@report_series/writeSeriesForGraph.m index 0d3123f74..8628dd30d 100644 --- a/matlab/reports/@report_series/writeSeriesForGraph.m +++ b/matlab/reports/@report_series/writeSeriesForGraph.m @@ -105,16 +105,7 @@ else ds = o.data(xrange); end -% if graphing data that is within zeroTol, set to zero, create report_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 - +thedata = setDataToZeroFromZeroTol(o, ds); fprintf(fid, '%%series %s\n\\addplot', o.data.name{:}); writeLineOptions(o, fid); fprintf(fid,'\ntable[row sep=crcr]{\nx y\\\\\n');