1 ## Copyright (C) 2000-2012 Auburn University. All rights reserved.
3 ## This file is part of Octave.
5 ## Octave program is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave program is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {[@var{idxvec}, @var{errmsg}] =} cellidx (@var{listvar}, @var{strlist})
21 ## Return indices of string entries in @var{listvar} that match strings
24 ## Both @var{listvar} and @var{strlist} may be passed as strings or
25 ## string matrices. If they are passed as string matrices, each entry
26 ## is processed by @code{deblank} prior to searching for the entries.
28 ## The first output is the vector of indices in @var{listvar}.
30 ## If @var{strlist} contains a string not in @var{listvar}, then
31 ## an error message is returned in @var{errmsg}. If only one output
32 ## argument is requested, then @var{cellidx} prints @var{errmsg} to the
33 ## screen and exits with an error.
36 ## deprecated in version 3.4
38 function [idxvec,errmsg] = cellidx (listvar, strlist)
40 persistent warned = false;
43 warning ("Octave:deprecated-function",
44 "cellidx is obsolete and will be removed from a future version of Octave; use ismember instead");
55 strlist{kk} = deblank (tmp(kk,:));
63 listvar{kk} = deblank (tmp(kk,:));
67 ## initialize size of idxvec (for premature return)
68 idxvec = zeros (length(strlist), 1);
71 if (! iscellstr (listvar))
72 errmsg = "listvar must be a list of strings";
73 elseif (! iscellstr (strlist))
74 errmsg = "strlist must be a list of strings";
85 nsigs = length(listvar);
86 for idx = 1:length(strlist)
87 signame = strlist{idx};
89 if (strcmp (signame, listvar{jdx}))
91 warning ("Duplicate signal name %s (%d,%d)\n",
92 listvar{jdx}, jdx, idxvec(idx));
99 errmsg = sprintf ("Did not find %s", signame);