# HG changeset patch # User Ben Abbott # Date 1223038513 -7200 # Node ID 9780ca97156e8fac00a5f2c330f179baf1298921 # Parent ad3b944fde43e8f4b189ca48650ce1cd9c4a277d conv.m: Correct row/col orientation of output diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2008-09-29 Ben Abbott + + * polynomial/conv.m: Correct row/col orientation of output. + 2008-09-24 John W. Eaton * plot/fplot.m: Call axis after calling plot. diff --git a/scripts/polynomial/conv.m b/scripts/polynomial/conv.m --- 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