Mercurial > hg > octave-lyh
changeset 6050:435294ca4ee6
[project @ 2006-10-13 17:42:21 by jwe]
author | jwe |
---|---|
date | Fri, 13 Oct 2006 17:42:21 +0000 |
parents | 04c2ad6d1679 |
children | 583c98eeeae2 |
files | scripts/ChangeLog scripts/general/ind2sub.m scripts/general/sub2ind.m |
diffstat | 3 files changed, 11 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2006-10-13 Etienne Grossmann <etienne@tyzx.com> + + * general/ind2sub.m, general/sub2ind.m: Handle empty indices. + 2006-10-12 Quentin Spencer <qspencer@ieee.org> * plot/sombrero.m: Only plot if nargout == 0. Otherwise, return data.
--- a/scripts/general/ind2sub.m +++ b/scripts/general/ind2sub.m @@ -29,10 +29,10 @@ function varargout = ind2sub (dims, ind) if (nargin == 2) - if (isvector (dims) && round (dims) == dims) - if (isnumeric (ind) && round (ind) == ind) + if (isvector (dims) && all (round (dims) == dims)) + if (isnumeric (ind) && all (round (ind) == ind)) ntot = prod (dims); - if (ind > 0 & ind <= ntot) + if (all (ind > 0 & ind <= ntot)) nd = length (dims); if (nargout > 0) vlen = nargout;
--- a/scripts/general/sub2ind.m +++ b/scripts/general/sub2ind.m @@ -30,7 +30,7 @@ function ind = sub2ind (dims, varargin) if (nargin > 1) - if (isvector (dims) && round (dims) == dims) + if (isvector (dims) && all (round (dims) == dims)) nd = length (dims); vlen = length (varargin); dims(vlen) = prod (dims(vlen:nd)); @@ -38,16 +38,16 @@ scale = cumprod (dims(:)); for i = 1:vlen arg = varargin{i}; - if (isnumeric (arg) && round (arg) == arg) + if (isnumeric (arg) && all (round (arg) == arg)) if (i == 1) - if (arg > 0 & arg <= dims(i)) + if (all (arg > 0 & arg <= dims(i))) ind = first_arg = arg; else error ("sub2ind: index out of range"); endif else if (prod (size (first_arg)) == prod (size (arg))) - if ((i > nd && arg == 1) || (arg > 0 & arg <= dims(i))) + if ((i > nd && arg == 1) || all (arg > 0 & arg <= dims(i))) ind(:) += scale(i-1) * (arg(:) - 1); else error ("sub2ind: index out of range");