Mercurial > hg > octave-nkf
diff scripts/polynomial/deconv.m @ 8159:ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Mon, 29 Sep 2008 13:36:17 -0400 |
parents | 83a8781b529d |
children | eb63fbe60fab |
line wrap: on
line diff
--- a/scripts/polynomial/deconv.m +++ b/scripts/polynomial/deconv.m @@ -49,6 +49,11 @@ lb = ly - la + 1; + ## Ensure A is oriented as Y. + if (diff (size (y)(1:2)) * diff (size (a)(1:2)) < 0) + a = permute (a, [2, 1]); + endif + if (ly > la) b = filter (y, a, [1, (zeros (1, ly - la))]); elseif (ly == la) @@ -61,7 +66,16 @@ if (ly == lc) r = y - conv (a, b); else - r = [(zeros (1, lc - ly)), y] - conv (a, b); + ## Respect the orientation of Y" + if (size (y, 1) <= size (y, 2)) + r = [(zeros (1, lc - ly)), y] - conv (a, b); + else + r = [(zeros (lc - ly, 1)); y] - conv (a, b); + endif + if (ly < la) + ## Trim the remainder is equal to the length of Y. + r = r(end-(length(y)-1):end); + endif endif endfunction @@ -72,13 +86,21 @@ %!test %! [b, r] = deconv ([3, 6], [1, 2, 3]); -%! assert(b == 0 && all (all (r == [0, 3, 6]))); +%! assert(b == 0 && all (all (r == [3, 6]))); %!test %! [b, r] = deconv ([3, 6], [1; 2; 3]); -%! assert(b == 0 && all (all (r == [0, 3, 6]))); +%! assert(b == 0 && all (all (r == [3, 6]))); + +%!test +%! [b,r] = deconv ([3; 6], [1; 2; 3]); +%! assert (b == 0 && all (all (r == [3; 6]))) -%!error [b, r] = deconv ([3, 6], [1, 2; 3, 4]);; +%!test +%! [b, r] = deconv ([3; 6], [1, 2, 3]); +%! assert (b == 0 && all (all (r == [3; 6]))) -%!error <number of rows must match> [b, r] = deconv ([3; 6], [1, 2, 3]); +%!error [b, r] = deconv ([3, 6], [1, 2; 3, 4]); +%!error [b, r] = deconv ([3, 6; 1, 2], [1, 2, 3]); +