Mercurial > jwe > octave
changeset 23827:3d67c7b99546
allow trapz to work on mixed row/column vectors (bug #33292)
* trapz.m: Check early for two vector arguments of possibly different
orientations and coerce them to columns. New tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 03 Aug 2017 08:41:19 -0400 |
parents | d69021d58a61 |
children | 9ceb1916eadf |
files | scripts/general/trapz.m |
diffstat | 1 files changed, 8 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/trapz.m Wed Aug 02 17:16:19 2017 -0400 +++ b/scripts/general/trapz.m Thu Aug 03 08:41:19 2017 -0400 @@ -72,6 +72,10 @@ have_xy = true; have_dim = true; elseif (nargin == 2) + if (isvector (x) && isvector (y)) + x = x(:); + y = y(:); + endif if (! size_equal (x, y) && isscalar (y)) dim = y; have_dim = true; @@ -127,6 +131,10 @@ %!assert (trapz (1:5), 12) +%!assert (trapz ([1:5], [1:5]), 12) +%!assert (trapz ([1:5], [1:5]'), 12) +%!assert (trapz ([1:5]', [1:5]'), 12) +%!assert (trapz ([1:5]', [1:5]), 12) %!assert (trapz (0:0.5:2,1:5), 6) %!assert (trapz ([1:5;1:5].',1), [12,12]) %!assert (trapz ([1:5;1:5],2), [12;12])