2017-10-10 10:05:59 +02:00
|
|
|
function dyntable(options_, title, headers, labels, values, label_width, val_width, val_precis, optional_header)
|
|
|
|
|
|
|
|
% Prints a table of results in main command window.
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2019-12-20 16:28:06 +01:00
|
|
|
% INPUTS
|
2017-10-10 10:05:59 +02:00
|
|
|
% - options_ [structure] Dynare options structure
|
|
|
|
% - title [string] Table title
|
|
|
|
% - headers [cell] labels for header row (each element is a row characater array)
|
|
|
|
% - labels [cell] labels for label column (each element is a row characater array)
|
|
|
|
% - values [double] matrix of values to display
|
|
|
|
% - label_width [integer] scalar, width of the label
|
|
|
|
% - val_width [integer] scalar, width of value column
|
|
|
|
% - val_precis [integer] scalar, precision of displayed values
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2019-12-20 16:28:06 +01:00
|
|
|
% OUTPUTS
|
2017-10-10 10:05:59 +02:00
|
|
|
% none
|
|
|
|
|
|
|
|
% Copyright (C) 2002-2018 Dynare Team
|
2008-08-01 20:53:30 +02:00
|
|
|
%
|
|
|
|
% 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
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2008-08-01 20:53:30 +02:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
if options_.noprint
|
2009-08-24 15:39:43 +02:00
|
|
|
return
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2009-08-24 15:39:43 +02:00
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
% Set width of label column
|
|
|
|
if isempty(label_width)
|
|
|
|
label_width = cellofchararraymaxlength(vertcat(headers{1}, labels))+2;
|
|
|
|
else
|
|
|
|
label_width = max(cellofchararraymaxlength(vertcat(headers{1}, labels))+2, label_width);
|
2015-04-22 15:26:03 +02:00
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
label_format_leftbound = sprintf('%%-%ds', label_width);
|
|
|
|
|
2011-04-18 10:49:55 +02:00
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
% Set width of other columns
|
2013-01-07 17:03:47 +01:00
|
|
|
if all(~isfinite(values))
|
|
|
|
values_length = 4;
|
|
|
|
else
|
|
|
|
values_length = max(ceil(max(max(log10(abs(values(isfinite(values))))))),1)+val_precis+1;
|
|
|
|
end
|
2015-04-22 15:26:03 +02:00
|
|
|
if any(values) < 0 %add one character for minus sign
|
2011-04-18 10:49:55 +02:00
|
|
|
values_length = values_length+1;
|
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
headers_length = cellofchararraymaxlength(headers(2:end));
|
|
|
|
if isempty(val_width)
|
|
|
|
val_width = max(headers_length, values_length)+2;
|
2015-04-22 15:26:03 +02:00
|
|
|
else
|
2017-10-10 10:05:59 +02:00
|
|
|
val_width = max(max(headers_length, values_length)+2, val_width);
|
2011-04-18 10:49:55 +02:00
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
value_format = sprintf('%%%d.%df', val_width, val_precis);
|
|
|
|
header_string_format = sprintf('%%%ds', val_width);
|
2011-04-18 10:49:55 +02:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
if length(title) > 0
|
2015-04-22 15:26:03 +02:00
|
|
|
fprintf('\n\n%s\n',title);
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
|
|
|
|
% Create and print header string
|
2016-05-31 20:56:59 +02:00
|
|
|
if nargin==9
|
|
|
|
disp(optional_header)
|
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
if length(headers) > 0
|
2017-10-10 10:05:59 +02:00
|
|
|
hh = sprintf(label_format_leftbound , headers{1});
|
|
|
|
for i=2:length(headers)
|
|
|
|
hh = [hh sprintf(header_string_format, headers{i})];
|
2005-02-18 20:54:39 +01:00
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
disp(hh)
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2016-05-31 20:56:59 +02:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
for i=1:size(values,1)
|
2017-10-10 10:05:59 +02:00
|
|
|
disp([sprintf(label_format_leftbound, labels{i}) sprintf(value_format, values(i,:))])
|
2015-04-22 15:26:03 +02:00
|
|
|
end
|