Skip to content
Snippets Groups Projects
Verified Commit 55b20200 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Allow indexing of the main members of dprior objects.

For example, Prior.lb(3) returns the lower bound of the prior distribution for the third parameter, assuming Prior is a dprior object.
parent c979544f
Branches
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ function p = subsref(o, S)
% Overload subsref method.
% Copyright © 2023-2024 Dynare Team
% Copyright © 2023-2025 Dynare Team
%
% This file is part of Dynare.
%
......@@ -22,7 +22,39 @@ function p = subsref(o, S)
switch S(1).type
case '.'
if ismember(S(1).subs, {'p1','p2','p3','p4','p5','p6','p7','lb','ub','trunc'})
p = builtin('subsref', o, S(1));
varargout{1} = builtin('subsref', o, S(1));
if length(S)>1 && strcmp(S(1).type, '()') && ~strcmp(S(1).subs, 'trunc')
S = shiftS(S,1);
if ~isempty(S)
varargout{1} = subsref(varargout{1}, S);
end
end
elseif strcmp(S(1).subs, 'isshape') && length(S)>1 && strcmp(S(2).type, '()') && length(S(2).subs)==2
if ischar(S(2).subs{1})
if ~isnumeric(S(2).subs{2}) || ~isscalar(S(2).subs{2}) || ~(abs(round(S(2).subs{2})-S(2).subs{2})<eps(1))
derror('dprior:wrongInputArguments', sprintf('Second input argument must be an integer scalar between 1 and %u', o.length()))
end
switch S(2).subs{1}
case 'uniform'
varargout{1} = ismember(S(2).subs{2}, o.iduniform);
case 'gaussian'
varargout{1} = ismember(S(2).subs{2}, o.idgaussian);
case 'gamma'
varargout{1} = ismember(S(2).subs{2}, o.idgamma);
case 'beta'
varargout{1} = ismember(S(2).subs{2}, o.idbeta);
case 'invgamma1'
varargout{1} = ismember(S(2).subs{2}, o.idinvgamma1);
case 'invgamma2'
varargout{1} = ismember(S(2).subs{2}, o.idinvgamma2);
case 'weibull'
varargout{1} = ismember(S(2).subs{2}, o.idweibull);
otherwise
derror('dprior:wrongInputArguments', sprintf('Unknown prior shape (%s).', S(2).subs{1}))
end
else
derror('dprior:wrongInputArguments', 'First input argument to ishape must be the name of a distribution (row char array).')
end
elseif isequal(S(1).subs, 'bounds') && length(S)==1
p = bounds(o, [], false);
elseif ismember(S(1).subs, {'deviate','length','isempty'})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment