[OctDev] isvector

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[OctDev] isvector

William Poetra Yoga H
I saw this here:
http://www.octave.org/octave-lists/archive/bug-octave.2005/msg00730.html

> I wrote it like this:
>
>   if (nargin == 1)
>     retval = (ismatrix (x) && ! isempty (x) && prod (size (x)) == length
(x));
>   else
>     usage ("isvector (x)");
>   endif
>
> Thanks,
>
> jwe

But wouldn't prod(size(x)) overflow? Would this be better:

function retval = isvector (x)

  if (nargin != 1)
    usage("isvector (x)");
  endif

  retval = 0;

  if ismatrix(x)
    s_x = size(x);
    if (s_x > 0)
      f_sx1 = find(s_x-1);
      if (isempty(f_sx1) || (length(f_sx1) == 1))
        retval = 1;
      endif
    endif
  endif

endfunction


William Poetra Yoga Hadisoeseno


               
__________________________________
Start your day with Yahoo! - Make it your home page!
http://www.yahoo.com/r/hs


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev
Reply | Threaded
Open this post in threaded view
|

Re: [OctDev] isvector

William Poetra Yoga H
I got another idea (basically the same as the previous one, but simpler):

function retval = isvector (x)

  retval = 0;
  if !ismatrix(x), return; endif
  s_x = size(x);
  if any(s_x < 1), return; endif
  if ((s_x == 1) || (length(find(s_x-1)) == 1))
    retval = 1;
  endif

endfunction

P.S.: Sorry, I didn't mean to flood the list with this kind of topics...


William Poetra Yoga Hadisoeseno


               
__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev