From 55ea513f745045d297c1403abacaaa91fdebbdbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Wed, 3 Jul 2013 14:54:05 +0200 Subject: [PATCH] Added broadcasting when assigning new data to a dynSeries object. *Examples* * ts.A(qq(1950,1):qq(1950,4)) = 1 will put ones for variable A in periods 1950Q1 to 1950Q4 * ts{'A','B'}(qq(1950,1):qq(1950,4)) = 1 will put ones for variables A and B in periods 1950Q1 to 1950Q4 * ts{'A','B'}(qq(1950,1):qq(1950,4)) = ones(4,1) will put ones(4,1) for variables A and B and sub-periods 1950Q1-1950Q4 * ts{'A','B'}(qq(1950,1):qq(1950,4)) = ones(1,2) will put ones(1,2) for variables A and B and each period between 1950Q1 and 1950Q4 --- matlab/@dynSeries/subsasgn.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/matlab/@dynSeries/subsasgn.m b/matlab/@dynSeries/subsasgn.m index 054a81547..3c1b176b7 100644 --- a/matlab/@dynSeries/subsasgn.m +++ b/matlab/@dynSeries/subsasgn.m @@ -167,11 +167,19 @@ switch length(S) if isequal(length(tdx),rows(B)) if isequal(columns(sA.data),columns(B)) sA.data(tdx,:) = B; + elseif isequal(size(B,2),1) + sA.data(tdx,:) = repmat(B,1,columns(sA.data)); 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.') + if isequal(columns(sA.data),columns(B)) && isequal(rows(B),1) + sA.data(tdx,:) = repmat(B,length(tdx),1); + elseif isequal(rows(B),1) + sA.data(tdx,:) = B + else + error('dynSeries::subsassgn: Dimension error! The number of periods on the left and right hand side must match.') + end end else error('dynSeries::subsasgn: The object on the right hand side must be a dynSeries object or a numeric array!')