From 29d19e4c2ee6094d21d5192698e3dd7d2d8cdd83 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Thu, 24 Oct 2019 11:28:03 +0200 Subject: [PATCH] only allow addData to be used once per table --- src/@report_data/report_data.m | 1 - src/@report_data/writeDataForTable.m | 23 +++-------------------- src/@report_table/addData.m | 5 ++++- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/@report_data/report_data.m b/src/@report_data/report_data.m index 043de46..4f9f4a2 100644 --- a/src/@report_data/report_data.m +++ b/src/@report_data/report_data.m @@ -19,7 +19,6 @@ classdef report_data < handle % along with Dynare. If not, see <http://www.gnu.org/licenses/>. properties (SetAccess = private) data = '' - tableSubSectionHeader = '' tableAlignRight = false tableRowColor = 'white' tableRowIndent = 0 diff --git a/src/@report_data/writeDataForTable.m b/src/@report_data/writeDataForTable.m index 1df33dc..34723fb 100644 --- a/src/@report_data/writeDataForTable.m +++ b/src/@report_data/writeDataForTable.m @@ -32,12 +32,6 @@ function writeDataForTable(o, fid, precision) % along with Dynare. If not, see <http://www.gnu.org/licenses/>. %% Validate options provided by user -assert(ischar(o.tableSubSectionHeader), '@report_data.writeDataForTable: tableSubSectionHeader must be a string'); -if isempty(o.tableSubSectionHeader) - assert(~isempty(o.data) && iscell(o.data), ... - '@report_data.writeDataForTable: must provide data as a cell'); -end - assert(ischar(o.tableRowColor), '@report_data.writeDataForTable: tableRowColor must be a string'); assert(isint(o.tableRowIndent) && o.tableRowIndent >= 0, ... '@report_data.writeDataForTable: tableRowIndent must be an integer >= 0'); @@ -53,20 +47,9 @@ rounding = 10^precision; %% Write Output fprintf(fid, '%% Table Data (report_data)\n'); -nrows = length(o.data{1}); -ncols = length(o.data); +[nrows, ncols] = size(o.data); for i = 1:nrows - if ~isempty(o.tableRowColor) && ~strcmpi(o.tableRowColor, 'white') - fprintf(fid, '\\rowcolor{%s}', o.tableRowColor); - else - fprintf(fid, '\\rowcolor{%s}', o.tableRowColor); - end - if ~isempty(o.tableSubSectionHeader) - fprintf(fid, '\\textbf{%s}', o.tableSubSectionHeader); - fprintf(fid, '%s', repmat(' &', 1, ncols-1)); - fprintf(fid, '\\\\%%\n'); - return - end + fprintf(fid, '\\rowcolor{%s}', o.tableRowColor); if o.tableAlignRight fprintf(fid, '\\multicolumn{1}{r}{'); end @@ -81,7 +64,7 @@ for i = 1:nrows fprintf(fid, '}'); end for j = 1:ncols - val = o.data{j}(i); + val = o.data(i,j); if iscell(val) val = val{:}; end diff --git a/src/@report_table/addData.m b/src/@report_table/addData.m index 9bb66c8..b17fe99 100644 --- a/src/@report_table/addData.m +++ b/src/@report_table/addData.m @@ -29,5 +29,8 @@ function o = addData(o, varargin) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -o.table_data{end+1} = report_data(varargin{:}); +if length(o.table_data) >= 1 + error('@report_table.addData: You can only use addData once per table') +end +o.table_data{1} = report_data(varargin{:}); end \ No newline at end of file -- GitLab