Rewrote @dynSeries/subsasgn.

The following syntaxes are now allowed:

ts{'VARIABLE_NAME'}(range) = data;

where range is a dynDates object and data is an array of doubles, or

ts{'VARIABLE_NAME'}(range) = TS{'OTHER_VARIABLE_NAME'}(range)

where ts and TS are dynSeries objects.
time-shift
Stéphane Adjemian (Charybdis) 2013-07-01 16:24:17 +02:00
parent b5c3ef2ade
commit 5ededa8848
1 changed files with 148 additions and 83 deletions

View File

@ -25,6 +25,10 @@ function A = subsasgn(A,S,B)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
merge_dynSeries_objects = 1;
switch length(S)
case 1
switch S(1).type
case '{}' % Multiple variable selection.
if ~isequal(numel(S(1).subs),numel(unique(S(1).subs)))
@ -110,17 +114,78 @@ switch S(1).type
end
end
case '()' % Date(s) selection
error('Not yet implemented!')
if isa(S(1).subs{1},'dynDates') || isa(S(1).subs{1},'dynDate')
[junk, tdx] = intersect(A.time.time,S(1).subs{1}.time,'rows');
if isa(B,'dynSeries')
[junk, tdy] = intersect(B.time.time,S(1).subs{1}.time,'rows');
if isempty(tdy)
error('dynSeries::subsasgn: Periods of the dynSeries objects on the left and right hand sides must intersect!')
end
if ~isequal(A.vobs,B.vobs)
error('dynSeries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
end
A.data(tdx,:) = B.data(tdy,:);
elseif isnumeric(B)
merge_dynSeries_objects = 0;
if isequal(length(tdx),rows(B))
if isequal(columns(A.data),columns(B))
A.data(tdx,:) = B;
else
error('dynSeries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
end
else
error('dynSeries::subsassgn: Dimension error! The number of periods on the left and right hand side must match.')
end
else
error('dynSeries::subsasgn: The object on the right hand side must be a dynSeries object or a numeric array!')
end
else
error('dynSeries::subsasgn: Wrong syntax!')
end
otherwise
error('dynSeries::subsasgn: Wrong syntax!')
end
case 2
merge_dynSeries_objects = 0;
if ((isequal(S(1).type,'{}') || isequal(S(1).type,'.')) && isequal(S(2).type,'()'))
sA = extract(A,S(1).subs{:});
if (isa(B,'dynSeries') && isequal(sA.vobs,B.vobs)) || (isnumeric(B) && isequal(sA.vobs,columns(B)))
if isa(S(2).subs{1},'dynDates') || isa(S(2).subs{1},'dynDate')
[junk, tdx] = intersect(sA.time.time,S(2).subs{1}.time,'rows');
if isa(B,'dynSeries')
[junk, tdy] = intersect(B.time.time,S(2).subs{1}.time,'rows');
if isempty(tdy)
error('dynSeries::subsasgn: Periods of the dynSeries objects on the left and right hand sides must intersect!')
end
sA.data(tdx,:) = B.data(tdy,:);
elseif isnumeric(B)
merge_dynSeries_objects = 0;
if isequal(length(tdx),rows(B))
if isequal(columns(sA.data),columns(B))
sA.data(tdx,:) = B;
else
error('dynSeries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
end
else
error('dynSeries::subsassgn: Dimension error! The number of periods on the left and right hand side must match.')
end
else
error('dynSeries::subsasgn: The object on the right hand side must be a dynSeries object or a numeric array!')
end
else
error('dynSeries::subsasgn: Wrong syntax!')
end
A = merge(A,sA);
else
error('dynSeries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
end
end
otherwise
error('dynSeries::subsasgn: Wrong syntax!')
end
if merge_dynSeries_objects
A = merge(A,B);
S = shiftS(S);
if ~isempty(S)
error('dynSeries::subsasgn: Wrong syntax!')
A = subsasgn(A, S, B);
end
%@test:1