annotate scripts/set/ismember.m @ 17744:d63878346099

maint: Update copyright notices for release.
author John W. Eaton <jwe@octave.org>
date Wed, 23 Oct 2013 22:09:27 -0400
parents bc924baa2c4e
children 89055521e04d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
1 ## Copyright (C) 2000-2013 Paul Kienzle
9345
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
2 ## Copyright (C) 2009 Jaroslav Hajek
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
3 ##
5181
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
4 ## This file is part of Octave.
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
5 ##
5181
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6730
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6730
diff changeset
9 ## your option) any later version.
5181
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
10 ##
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
14 ## General Public License for more details.
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
15 ##
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6730
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6730
diff changeset
18 ## <http://www.gnu.org/licenses/>.
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
19
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
21 ## @deftypefn {Function File} {@var{tf} =} ismember (@var{A}, @var{s})
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
22 ## @deftypefnx {Function File} {[@var{tf}, @var{S_idx}] =} ismember (@var{A}, @var{s})
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
23 ## @deftypefnx {Function File} {[@var{tf}, @var{S_idx}] =} ismember (@var{A}, @var{s}, "rows")
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
24 ## Return a logical matrix @var{tf} with the same shape as @var{A} which is
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
25 ## true (1) if @code{A(i,j)} is in @var{s} and false (0) if it is not. If a
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
26 ## second output argument is requested, the index into @var{s} of each of the
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
27 ## matching elements is also returned.
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
28 ##
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
29 ## @example
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
30 ## @group
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
31 ## a = [3, 10, 1];
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
32 ## s = [0:9];
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
33 ## [tf, s_idx] = ismember (a, s)
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
34 ## @result{} tf = [1, 0, 1]
9276
f5e4b5fd1f1e Update ismember examples to remove incorrect reference to residue function
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
35 ## @result{} s_idx = [4, 0, 2]
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
36 ## @end group
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
37 ## @end example
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
38 ##
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
39 ## The inputs, @var{A} and @var{s}, may also be cell arrays.
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
40 ##
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
41 ## @example
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
42 ## @group
14359
7277fe922e99 doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
43 ## a = @{"abc"@};
7277fe922e99 doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
44 ## s = @{"abc", "def"@};
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
45 ## [tf, s_idx] = ismember (a, s)
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
46 ## @result{} tf = [1, 0]
9276
f5e4b5fd1f1e Update ismember examples to remove incorrect reference to residue function
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
47 ## @result{} s_idx = [1, 0]
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
48 ## @end group
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
49 ## @end example
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
50 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 14868
diff changeset
51 ## With the optional third argument @qcode{"rows"}, and matrices
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
52 ## @var{A} and @var{s} with the same number of columns, compare rows in
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
53 ## @var{A} with the rows in @var{s}.
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
54 ##
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
55 ## @example
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
56 ## @group
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
57 ## a = [1:3; 5:7; 4:6];
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
58 ## s = [0:2; 1:3; 2:4; 3:5; 4:6];
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
59 ## [tf, s_idx] = ismember (a, s, "rows")
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
60 ## @result{} tf = logical ([1; 0; 1])
9276
f5e4b5fd1f1e Update ismember examples to remove incorrect reference to residue function
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
61 ## @result{} s_idx = [2; 0; 5];
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
62 ## @end group
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
63 ## @end example
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
64 ##
8286
6f2d95255911 fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7883
diff changeset
65 ## @seealso{unique, union, intersect, setxor, setdiff}
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
66 ## @end deftypefn
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
67
7129
363ffc8a5c80 [project @ 2007-11-08 15:20:11 by jwe]
jwe
parents: 7128
diff changeset
68 ## Author: Paul Kienzle <pkienzle@users.sf.net>
363ffc8a5c80 [project @ 2007-11-08 15:20:11 by jwe]
jwe
parents: 7128
diff changeset
69 ## Author: Søren Hauberg <hauberg@gmail.com>
363ffc8a5c80 [project @ 2007-11-08 15:20:11 by jwe]
jwe
parents: 7128
diff changeset
70 ## Author: Ben Abbott <bpabbott@mac.com>
5181
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
71 ## Adapted-by: jwe
9345
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
72 ## Reimplemented using lookup & unique: Jaroslav Hajek <highegg@gmail.com>
5181
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
73
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
74 function [tf, a_idx] = ismember (A, s, varargin)
10088
5edee330d4cb better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9924
diff changeset
75
5edee330d4cb better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9924
diff changeset
76 if (nargin < 2 || nargin > 3)
5edee330d4cb better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9924
diff changeset
77 print_usage ();
5edee330d4cb better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9924
diff changeset
78 endif
5edee330d4cb better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9924
diff changeset
79
13228
e8c52b442a99 Allow logical inputs to ismember() (Bug #33531).
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
80 ## lookup() does not handle logical values
e8c52b442a99 Allow logical inputs to ismember() (Bug #33531).
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
81 if (islogical (A))
e8c52b442a99 Allow logical inputs to ismember() (Bug #33531).
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
82 A = uint8 (A);
e8c52b442a99 Allow logical inputs to ismember() (Bug #33531).
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
83 endif
e8c52b442a99 Allow logical inputs to ismember() (Bug #33531).
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
84 if (islogical (s))
e8c52b442a99 Allow logical inputs to ismember() (Bug #33531).
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
85 s = uint8 (s);
e8c52b442a99 Allow logical inputs to ismember() (Bug #33531).
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
86 endif
e8c52b442a99 Allow logical inputs to ismember() (Bug #33531).
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
87
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
88 [A, s] = validargs ("ismember", A, s, varargin{:});
5181
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
89
9345
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
90 if (nargin == 2)
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
91 s = s(:);
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
92 ## We do it this way, because we expect the array to be often sorted.
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
93 if (issorted (s))
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
94 is = [];
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
95 else
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
96 [s, is] = sort (s);
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
97 endif
9364
6c255e51ef7e improve & fix ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9345
diff changeset
98
9924
d0d6ff39db54 simplify ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9735
diff changeset
99 ## sort out NaNs in table
9364
6c255e51ef7e improve & fix ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9345
diff changeset
100 if (isreal (s) && ! isempty (s) && isnan (s(end)))
6c255e51ef7e improve & fix ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9345
diff changeset
101 s = s(1:end - sum (isnan (s)));
6c255e51ef7e improve & fix ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9345
diff changeset
102 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
103
9345
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
104 if (nargout > 1)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
105 a_idx = lookup (s, A, "m");
9345
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
106 tf = logical (a_idx);
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
107 if (! isempty (is))
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
108 a_idx(tf) = is (a_idx(tf));
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
109 endif
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
110 else
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
111 tf = lookup (s, A, "b");
9345
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
112 endif
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
113
10088
5edee330d4cb better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9924
diff changeset
114 else
5edee330d4cb better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9924
diff changeset
115
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
116 if (isempty (A) || isempty (s))
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
117 tf = false (rows (A), 1);
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
118 a_idx = zeros (rows (A), 1);
9733
aab4f2aa9ed9 make ismember more matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 9364
diff changeset
119 else
9345
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
120
9733
aab4f2aa9ed9 make ismember more matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 9364
diff changeset
121 ## FIXME: lookup does not support "rows", so we just use unique.
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
122 [xx, ii, jj] = unique ([A; s], "rows", "last");
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
123 na = rows (A);
9733
aab4f2aa9ed9 make ismember more matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 9364
diff changeset
124 jj = ii(jj(1:na));
aab4f2aa9ed9 make ismember more matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 9364
diff changeset
125 tf = jj > na;
9345
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
126
9733
aab4f2aa9ed9 make ismember more matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 9364
diff changeset
127 if (nargout > 1)
aab4f2aa9ed9 make ismember more matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 9364
diff changeset
128 a_idx = max (0, jj - na);
aab4f2aa9ed9 make ismember more matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 9364
diff changeset
129 endif
aab4f2aa9ed9 make ismember more matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 9364
diff changeset
130
9345
dbc61d4e428d optimize ismember
Jaroslav Hajek <highegg@gmail.com>
parents: 9276
diff changeset
131 endif
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
132 endif
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
133
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
134 endfunction
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
135
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
136
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
137 %!assert (ismember ({""}, {"abc", "def"}), false)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
138 %!assert (ismember ("abc", {"abc", "def"}), true)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
139 %!assert (isempty (ismember ([], [1, 2])), true)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
140 %!assert (isempty (ismember ({}, {'a', 'b'})), true)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
141 %!assert (ismember ("", {"abc", "def"}), false)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
142 %!fail ("ismember ([], {1, 2})")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
143 %!fail ("ismember ({[]}, {1, 2})")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
144 %!fail ("ismember ({}, {1, 2})")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
145 %!fail ("ismember ({1}, {'1', '2'})")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
146 %!fail ("ismember (1, 'abc')")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
147 %!fail ("ismember ({'1'}, {'1' '2'},'rows')")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
148 %!fail ("ismember ([1 2 3], [5 4 3 1], 'rows')")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
149 %!assert (ismember ({"foo", "bar"}, {"foobar"}), [false false])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
150 %!assert (ismember ({"foo"}, {"foobar"}), false)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
151 %!assert (ismember ({"bar"}, {"foobar"}), false)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
152 %!assert (ismember ({"bar"}, {"foobar", "bar"}), true)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
153 %!assert (ismember ({"foo", "bar"}, {"foobar", "bar"}), [false true])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
154 %!assert (ismember ({"xfb", "f", "b"}, {"fb", "b"}), [false false true])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
155 %!assert (ismember ("1", "0123456789."), true)
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
156
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
157 %!test
7652
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
158 %! [result, a_idx] = ismember ([1, 2], []);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
159 %! assert (result, [false false])
7652
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
160 %! assert (a_idx, [0, 0]);
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
161
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
162 %!test
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
163 %! [result, a_idx] = ismember ([], [1, 2]);
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
164 %! assert (result, logical ([]))
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
165 %! assert (a_idx, []);
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
166
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
167 %!test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
168 %! [result, a_idx] = ismember ({"a", "b"}, "");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
169 %! assert (result, [false false])
7652
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
170 %! assert (a_idx, [0, 0]);
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
171
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
172 %!test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
173 %! [result, a_idx] = ismember ({"a", "b"}, {});
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
174 %! assert (result, [false false])
7652
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
175 %! assert (a_idx, [0, 0]);
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
176
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
177 %!test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
178 %! [result, a_idx] = ismember ("", {"a", "b"});
7652
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
179 %! assert (result, false)
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
180 %! assert (a_idx, 0);
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
181
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
182 %!test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
183 %! [result, a_idx] = ismember ({}, {"a", "b"});
7652
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
184 %! assert (result, logical ([]))
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
185 %! assert (a_idx, []);
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
186
b5731e43283a ismember: correctly size idx output for empty args
John W. Eaton <jwe@octave.org>
parents: 7129
diff changeset
187 %!test
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
188 %! [result, a_idx] = ismember ([1 2 3 4 5], [3]);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
189 %! assert (result, logical ([0 0 1 0 0]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
190 %! assert (a_idx , [0 0 1 0 0]);
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
191
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
192 %!test
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
193 %! [result, a_idx] = ismember ([1 6], [1 2 3 4 5 1 6 1]);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
194 %! assert (result, [true true]);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
195 %! assert (a_idx(2), 7);
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
196
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
197 %!test
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
198 %! [result, a_idx] = ismember ([3,10,1], [0,1,2,3,4,5,6,7,8,9]);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
199 %! assert (result, [true false true]);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
200 %! assert (a_idx, [4, 0, 2]);
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
201
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
202 %!test
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
203 %! [result, a_idx] = ismember ("1.1", "0123456789.1");
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
204 %! assert (result, [true true true]);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
205 %! assert (a_idx, [12, 11, 12]);
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
206
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
207 %!test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
208 %! [result, a_idx] = ismember ([1:3; 5:7; 4:6], [0:2; 1:3; 2:4; 3:5; 4:6], "rows");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
209 %! assert (result, [true; false; true]);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
210 %! assert (a_idx, [2; 0; 5]);
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
211
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
212 %!test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
213 %! [result, a_idx] = ismember ([1.1,1.2,1.3; 2.1,2.2,2.3; 10,11,12], [1.1,1.2,1.3; 10,11,12; 2.12,2.22,2.32], "rows");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
214 %! assert (result, [true; false; true]);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
215 %! assert (a_idx, [1; 0; 2]);
7128
73308b8f8777 [project @ 2007-11-08 03:55:04 by jwe]
jwe
parents: 7077
diff changeset
216