Skip to content
Snippets Groups Projects
Verified Commit 29d19e4c authored by Houtan Bastani's avatar Houtan Bastani
Browse files

only allow addData to be used once per table

parent ef345742
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,6 @@ classdef report_data < handle ...@@ -19,7 +19,6 @@ classdef report_data < handle
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
properties (SetAccess = private) properties (SetAccess = private)
data = '' data = ''
tableSubSectionHeader = ''
tableAlignRight = false tableAlignRight = false
tableRowColor = 'white' tableRowColor = 'white'
tableRowIndent = 0 tableRowIndent = 0
......
...@@ -32,12 +32,6 @@ function writeDataForTable(o, fid, precision) ...@@ -32,12 +32,6 @@ function writeDataForTable(o, fid, precision)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
%% Validate options provided by user %% 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(ischar(o.tableRowColor), '@report_data.writeDataForTable: tableRowColor must be a string');
assert(isint(o.tableRowIndent) && o.tableRowIndent >= 0, ... assert(isint(o.tableRowIndent) && o.tableRowIndent >= 0, ...
'@report_data.writeDataForTable: tableRowIndent must be an integer >= 0'); '@report_data.writeDataForTable: tableRowIndent must be an integer >= 0');
...@@ -53,20 +47,9 @@ rounding = 10^precision; ...@@ -53,20 +47,9 @@ rounding = 10^precision;
%% Write Output %% Write Output
fprintf(fid, '%% Table Data (report_data)\n'); fprintf(fid, '%% Table Data (report_data)\n');
nrows = length(o.data{1}); [nrows, ncols] = size(o.data);
ncols = length(o.data);
for i = 1:nrows for i = 1:nrows
if ~isempty(o.tableRowColor) && ~strcmpi(o.tableRowColor, 'white') fprintf(fid, '\\rowcolor{%s}', o.tableRowColor);
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
if o.tableAlignRight if o.tableAlignRight
fprintf(fid, '\\multicolumn{1}{r}{'); fprintf(fid, '\\multicolumn{1}{r}{');
end end
...@@ -81,7 +64,7 @@ for i = 1:nrows ...@@ -81,7 +64,7 @@ for i = 1:nrows
fprintf(fid, '}'); fprintf(fid, '}');
end end
for j = 1:ncols for j = 1:ncols
val = o.data{j}(i); val = o.data(i,j);
if iscell(val) if iscell(val)
val = val{:}; val = val{:};
end end
......
...@@ -29,5 +29,8 @@ function o = addData(o, varargin) ...@@ -29,5 +29,8 @@ function o = addData(o, varargin)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % 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 end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment