1 function [resu, idx] = isfield(df, name, strict)
4 %# @deftypefn {Function File} [@var{resu}, @var{idx}] = isfield
5 %# (@var{df}, @var{name}, @var{strict})
6 %# Return true if the expression @var{df} is a dataframe and it
7 %# includes an element matching @var{name}. If @var{name} is a cell
8 %# array, a logical array of equal dimension is returned. @var{idx}
9 %# contains the column indexes of number of fields matching
10 %# @var{name}. To enforce strict matching instead of regexp matching,
11 %# set the third argument to 'true'.
14 %% Copyright (C) 2009-2012 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
16 %% This file is part of Octave.
18 %% Octave is free software; you can redistribute it and/or
19 %% modify it under the terms of the GNU General Public
20 %% License as published by the Free Software Foundation;
21 %% either version 2, or (at your option) any later version.
23 %% Octave is distributed in the hope that it will be useful,
24 %% but WITHOUT ANY WARRANTY; without even the implied
25 %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
26 %% PURPOSE. See the GNU General Public License for more
29 %% You should have received a copy of the GNU General Public
30 %% License along with Octave; see the file COPYING. If not,
31 %% write to the Free Software Foundation, 51 Franklin Street -
32 %% Fifth Floor, Boston, MA 02110-1301, USA.
35 %# $Id: isfield.m 9585 2012-02-05 15:32:46Z cdemills $
38 if !isa(df, 'dataframe'),
42 if nargin <2 || nargin > 3,
47 if 2 == nargin, strict = false; endif
50 if strict, %# use strmatch to get indexes
51 for indi = size(name, 1):-1:1,
52 dummy = strmatch(name(indi, :), df._name{2}, "exact");
53 resu(indi, 1) = !isempty(dummy);
54 for indj = 1:length(dummy),
55 idx(indi, indj) = dummy(indj);
59 for indi = size(name, 1):-1:1,
61 dummy = df_name2idx(df._name{2}, name(indi, :), \
62 df._cnt(2), 'column');
63 resu(indi, 1) = !isempty(dummy);
64 for indj = 1:length(dummy),
65 idx(indi, indj) = dummy(indj);
68 resu(indi, 1) = false; idx(indi, 1) = 0;
72 elseif isa(name, 'cell'),
73 if strict, %# use strmatch to get indexes
74 for indi = size(name, 1):-1:1,
75 dummy = strmatch(name{indi}, df._name{2}, "exact");
76 resu{indi, 1} = !isempty(dummy);
80 for indi = length(name):-1:1,
82 dummy = df_name2idx(df._name{2}, name{indi}, \
83 df._cnt(2), 'column');
85 resu{indi, 1} = !isempty(dummy); idx{indi, 1} = dummy;
87 resu{indi, 1} = false; cnt{indi, 1} = 0;