Mercurial > hg > octave-lyh
comparison src/data.cc @ 3369:f37ca3017116
[project @ 1999-11-21 16:26:02 by jwe]
author | jwe |
---|---|
date | Sun, 21 Nov 1999 16:26:08 +0000 |
parents | 4f40efa995c1 |
children | 36405da8e173 |
comparison
equal
deleted
inserted
replaced
3368:a4cd1e9d9962 | 3369:f37ca3017116 |
---|---|
48 #ifndef ABS | 48 #ifndef ABS |
49 #define ABS(x) (((x) < 0) ? (-x) : (x)) | 49 #define ABS(x) (((x) < 0) ? (-x) : (x)) |
50 #endif | 50 #endif |
51 | 51 |
52 DEFUN (all, args, , | 52 DEFUN (all, args, , |
53 "all (X): are all elements of X nonzero?") | 53 "-*- texinfo -*-\n\ |
54 @deftypefn {Built-in Function} {} all (@var{x})\n\ | |
55 The function @code{all} behaves like the function @code{any}, except\n\ | |
56 that it returns true only if all the elements of a vector, or all the\n\ | |
57 elements in a column of a matrix, are nonzero.\n\ | |
58 @end deftypefn") | |
54 { | 59 { |
55 octave_value_list retval; | 60 octave_value_list retval; |
56 | 61 |
57 int nargin = args.length (); | 62 int nargin = args.length (); |
58 | 63 |
63 | 68 |
64 return retval; | 69 return retval; |
65 } | 70 } |
66 | 71 |
67 DEFUN (any, args, , | 72 DEFUN (any, args, , |
68 "any (X): are any elements of X nonzero?") | 73 "-*- texinfo -*-\n\ |
74 @deftypefn {Built-in Function} {} any (@var{x})\n\ | |
75 For a vector argument, return 1 if any element of the vector is\n\ | |
76 nonzero.\n\ | |
77 \n\ | |
78 For a matrix argument, return a row vector of ones and\n\ | |
79 zeros with each element indicating whether any of the elements of the\n\ | |
80 corresponding column of the matrix are nonzero. For example,\n\ | |
81 \n\ | |
82 @example\n\ | |
83 @group\n\ | |
84 any (eye (2, 4))\n\ | |
85 @result{} [ 1, 1, 0, 0 ]\n\ | |
86 @end group\n\ | |
87 @end example\n\ | |
88 \n\ | |
89 To see if any of the elements of a matrix are nonzero, you can use a\n\ | |
90 statement like\n\ | |
91 \n\ | |
92 @example\n\ | |
93 any (any (a))\n\ | |
94 @end example\n\ | |
95 @end deftypefn") | |
69 { | 96 { |
70 octave_value_list retval; | 97 octave_value_list retval; |
71 | 98 |
72 int nargin = args.length (); | 99 int nargin = args.length (); |
73 | 100 |
492 | 519 |
493 return retval; | 520 return retval; |
494 } | 521 } |
495 | 522 |
496 DEFUN (diag, args, , | 523 DEFUN (diag, args, , |
497 "diag (X [,k]): form/extract diagonals") | 524 "-*- texinfo -*-\n\ |
525 @deftypefn {Built-in Function} {} diag (@var{v}, @var{k})\n\ | |
526 Return a diagonal matrix with vector @var{v} on diagonal @var{k}. The\n\ | |
527 second argument is optional. If it is positive, the vector is placed on\n\ | |
528 the @var{k}-th super-diagonal. If it is negative, it is placed on the\n\ | |
529 @var{-k}-th sub-diagonal. The default value of @var{k} is 0, and the\n\ | |
530 vector is placed on the main diagonal. For example,\n\ | |
531 \n\ | |
532 @example\n\ | |
533 @group\n\ | |
534 diag ([1, 2, 3], 1)\n\ | |
535 @result{} 0 1 0 0\n\ | |
536 0 0 2 0\n\ | |
537 0 0 0 3\n\ | |
538 0 0 0 0\n\ | |
539 @end group\n\ | |
540 @end example\n\ | |
541 @end deftypefn") | |
498 { | 542 { |
499 octave_value_list retval; | 543 octave_value_list retval; |
500 | 544 |
501 int nargin = args.length (); | 545 int nargin = args.length (); |
502 | 546 |
931 | 975 |
932 return retval; | 976 return retval; |
933 } | 977 } |
934 | 978 |
935 DEFUN (ones, args, , | 979 DEFUN (ones, args, , |
936 "ones (N), ones (N, M), ones (X): create a matrix of all ones") | 980 "-*- texinfo -*-\n\ |
981 @deftypefn {Built-in Function} {} ones (@var{x})\n\ | |
982 @deftypefnx {Built-in Function} {} ones (@var{n}, @var{m})\n\ | |
983 Return a matrix whose elements are all 1. The arguments are handled\n\ | |
984 the same as the arguments for @code{eye}.\n\ | |
985 \n\ | |
986 If you need to create a matrix whose values are all the same, you should\n\ | |
987 use an expression like\n\ | |
988 \n\ | |
989 @example\n\ | |
990 val_matrix = val * ones (n, m)\n\ | |
991 @end example\n\ | |
992 @end deftypefn") | |
937 { | 993 { |
938 return fill_matrix (args, 1.0, "ones"); | 994 return fill_matrix (args, 1.0, "ones"); |
939 } | 995 } |
940 | 996 |
941 DEFUN (zeros, args, , | 997 DEFUN (zeros, args, , |
942 "zeros (N), zeros (N, M), zeros (X): create a matrix of all zeros") | 998 "-*- texinfo -*-\n\ |
999 @deftypefn {Built-in Function} {} zeros (@var{x})\n\ | |
1000 @deftypefnx {Built-in Function} {} zeros (@var{n}, @var{m})\n\ | |
1001 Return a matrix whose elements are all 0. The arguments are handled\n\ | |
1002 the same as the arguments for @code{eye}.\n\ | |
1003 @end deftypefn") | |
943 { | 1004 { |
944 return fill_matrix (args, 0.0, "zeros"); | 1005 return fill_matrix (args, 0.0, "zeros"); |
945 } | 1006 } |
946 | 1007 |
947 static Matrix | 1008 static Matrix |
958 | 1019 |
959 return m; | 1020 return m; |
960 } | 1021 } |
961 | 1022 |
962 DEFUN (eye, args, , | 1023 DEFUN (eye, args, , |
963 "eye (N), eye (N, M), eye (X): create an identity matrix") | 1024 "-*- texinfo -*-\n\ |
1025 @deftypefn {Built-in Function} {} eye (@var{x})\n\ | |
1026 @deftypefnx {Built-in Function} {} eye (@var{n}, @var{m})\n\ | |
1027 Return an identity matrix. If invoked with a single scalar argument,\n\ | |
1028 @code{eye} returns a square matrix with the dimension specified. If you\n\ | |
1029 supply two scalar arguments, @code{eye} takes them to be the number of\n\ | |
1030 rows and columns. If given a vector with two elements, @code{eye} uses\n\ | |
1031 the values of the elements as the number of rows and columns,\n\ | |
1032 respectively. For example,\n\ | |
1033 \n\ | |
1034 @example\n\ | |
1035 @group\n\ | |
1036 eye (3)\n\ | |
1037 @result{} 1 0 0\n\ | |
1038 0 1 0\n\ | |
1039 0 0 1\n\ | |
1040 @end group\n\ | |
1041 @end example\n\ | |
1042 \n\ | |
1043 The following expressions all produce the same result:\n\ | |
1044 \n\ | |
1045 @example\n\ | |
1046 @group\n\ | |
1047 eye (2)\n\ | |
1048 @equiv{}\n\ | |
1049 eye (2, 2)\n\ | |
1050 @equiv{}\n\ | |
1051 eye (size ([1, 2; 3, 4])\n\ | |
1052 @end group\n\ | |
1053 @end example\n\ | |
1054 \n\ | |
1055 For compatibility with @sc{Matlab}, calling @code{eye} with no arguments\n\ | |
1056 is equivalent to calling it with an argument of 1.\n\ | |
1057 @end deftypefn") | |
964 { | 1058 { |
965 octave_value retval; | 1059 octave_value retval; |
966 | 1060 |
967 int nargin = args.length (); | 1061 int nargin = args.length (); |
968 | 1062 |
999 | 1093 |
1000 return retval; | 1094 return retval; |
1001 } | 1095 } |
1002 | 1096 |
1003 DEFUN (linspace, args, , | 1097 DEFUN (linspace, args, , |
1004 "usage: linspace (x1, x2, n)\n\ | 1098 "-*- texinfo -*-\n\ |
1005 \n\ | 1099 @deftypefn {Built-in Function} {} linspace (@var{base}, @var{limit}, @var{n})\n\ |
1006 Return a vector of n equally spaced points between x1 and x2\n\ | 1100 Return a row vector with @var{n} linearly spaced elements between\n\ |
1007 inclusive.\n\ | 1101 @var{base} and @var{limit}. The number of elements, @var{n}, must be\n\ |
1008 \n\ | 1102 greater than 1. The @var{base} and @var{limit} are always included in\n\ |
1009 If the final argument is omitted, n = 100 is assumed.\n\ | 1103 the range. If @var{base} is greater than @var{limit}, the elements are\n\ |
1010 \n\ | 1104 stored in decreasing order. If the number of points is not specified, a\n\ |
1011 All three arguments must be scalars.\n\ | 1105 value of 100 is used.\n\ |
1012 \n\ | 1106 \n\ |
1013 See also: logspace") | 1107 The @code{linspace} function always returns a row vector, regardless of\n\ |
1108 the value of @code{prefer_column_vectors}.\n\ | |
1109 @end deftypefn") | |
1014 { | 1110 { |
1015 octave_value_list retval; | 1111 octave_value_list retval; |
1016 | 1112 |
1017 int nargin = args.length (); | 1113 int nargin = args.length (); |
1018 | 1114 |