Mercurial > hg > octave-terminal
changeset 11864:9780ca97156e release-3-0-x
conv.m: Correct row/col orientation of output
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Fri, 03 Oct 2008 14:55:13 +0200 |
parents | ad3b944fde43 |
children | 78cf5edb69ce |
files | scripts/ChangeLog scripts/polynomial/conv.m |
diffstat | 2 files changed, 47 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2008-09-29 Ben Abbott <bpabbott@mac.com> + + * polynomial/conv.m: Correct row/col orientation of output. + 2008-09-24 John W. Eaton <jwe@octave.org> * plot/fplot.m: Call axis after calling plot.
--- a/scripts/polynomial/conv.m +++ b/scripts/polynomial/conv.m @@ -47,29 +47,62 @@ ly = la + lb - 1; - ## Ensure that both vectors are row vectors. - if (rows (a) > 1) - a = reshape (a, 1, la); - endif - if (rows (b) > 1) - b = reshape (b, 1, lb); - endif - ## Use the shortest vector as the coefficent vector to filter. + ## Preserve the row/column orientation of the longer input. if (la < lb) if (ly > lb) - x = [b, (zeros (1, ly - lb))]; + if (size (b, 1) <= size (b, 2)) + x = [b, (zeros (1, ly - lb))]; + else + x = [b; (zeros (ly - lb, 1))]; + endif else x = b; endif y = filter (a, 1, x); else if(ly > la) - x = [a, (zeros (1, ly - la))]; + if (size (a, 1) <= size (a, 2)) + x = [a, (zeros (1, ly - la))]; + else + x = [a; (zeros (ly - la, 1))]; + endif else x = a; endif y = filter (b, 1, x); endif +%!test +%! a = 1:10; +%! b = 1:3; +%! c = conv (a, b); +%! assert (size(c), [1, numel(a)+numel(b)-1]) +%!test +%! a = (1:10).'; +%! b = 1:3; +%! c = conv (a, b); +%! assert (size(c), [numel(a)+numel(b)-1, 1]) +%!test +%! a = 1:10; +%! b = (1:3).'; +%! c = conv (a, b); +%! assert (size(c), [1, numel(a)+numel(b)-1]) + +%!test +%! b = 1:10; +%! a = 1:3; +%! c = conv (a, b); +%! assert (size(c), [1, numel(a)+numel(b)-1]) +%!test +%! b = (1:10).'; +%! a = 1:3; +%! c = conv (a, b); +%! assert (size(c), [numel(a)+numel(b)-1, 1]) +%!test +%! b = 1:10; +%! a = (1:3).'; +%! c = conv (a, b); +%! assert (size(c), [1, numel(a)+numel(b)-1]) + endfunction