Mercurial > hg > octave-lyh
comparison src/data.cc @ 4741:e44d0ac643a5
[project @ 2004-02-05 21:57:50 by jwe]
author | jwe |
---|---|
date | Thu, 05 Feb 2004 21:57:51 +0000 |
parents | 7bd3748e2735 |
children | a308566c8b42 |
comparison
equal
deleted
inserted
replaced
4740:65f30438c2a3 | 4741:e44d0ac643a5 |
---|---|
790 "-*- texinfo -*-\n\ | 790 "-*- texinfo -*-\n\ |
791 @deftypefn {Built-in Function} {} size (@var{a}, @var{n})\n\ | 791 @deftypefn {Built-in Function} {} size (@var{a}, @var{n})\n\ |
792 Return the number rows and columns of @var{a}.\n\ | 792 Return the number rows and columns of @var{a}.\n\ |
793 \n\ | 793 \n\ |
794 With one input argument and one output argument, the result is returned\n\ | 794 With one input argument and one output argument, the result is returned\n\ |
795 in a 2 element row vector. If there are two output arguments, the\n\ | 795 in a row vector. If there are multiple output arguments, the number of\n\ |
796 number of rows is assigned to the first, and the number of columns to\n\ | 796 rows is assigned to the first, and the number of columns to the second,\n\ |
797 the second. For example,\n\ | 797 etc. For example,\n\ |
798 \n\ | 798 \n\ |
799 @example\n\ | 799 @example\n\ |
800 @group\n\ | 800 @group\n\ |
801 size ([1, 2; 3, 4; 5, 6])\n\ | 801 size ([1, 2; 3, 4; 5, 6])\n\ |
802 @result{} [ 3, 2 ]\n\ | 802 @result{} [ 3, 2 ]\n\ |
805 @result{} nr = 3\n\ | 805 @result{} nr = 3\n\ |
806 @result{} nc = 2\n\ | 806 @result{} nc = 2\n\ |
807 @end group\n\ | 807 @end group\n\ |
808 @end example\n\ | 808 @end example\n\ |
809 \n\ | 809 \n\ |
810 If given a second argument of either 1 or 2, @code{size} will return\n\ | 810 If given a second argument, @code{size} will return the size of the\n\ |
811 only the row or column dimension. For example\n\ | 811 corresponding dimension. For example\n\ |
812 \n\ | 812 \n\ |
813 @example\n\ | 813 @example\n\ |
814 size ([1, 2; 3, 4; 5, 6], 2)\n\ | 814 size ([1, 2; 3, 4; 5, 6], 2)\n\ |
815 @result{} 2\n\ | 815 @result{} 2\n\ |
816 @end example\n\ | 816 @end example\n\ |
850 | 850 |
851 if (error_state) | 851 if (error_state) |
852 error ("size: expecting scalar as second argument"); | 852 error ("size: expecting scalar as second argument"); |
853 else | 853 else |
854 { | 854 { |
855 if (nd == 1) | 855 dim_vector dv = args(0).dims (); |
856 retval(0) = args(0).rows (); | 856 |
857 else if (nd == 2) | 857 if (nd > 0 && nd <= dv.length ()) |
858 retval(0) = args(0).columns (); | 858 retval(0) = dv(nd-1); |
859 else | 859 else |
860 error ("size: invalid second argument -- expecting 1 or 2"); | 860 error ("size: requested dimension (= %d) out of range", nd); |
861 } | 861 } |
862 } | 862 } |
863 else | 863 else |
864 print_usage ("size"); | 864 print_usage ("size"); |
865 | 865 |