0
|
1 ## Copyright (C) 2000 Etienne Grossman |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2 of the License, or |
|
6 ## (at your option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, |
|
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 ## GNU General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; if not, write to the Free Software |
|
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 ## t = rmfield(s,key1,...) |
|
18 ## |
|
19 ## Removes key1, key2, ... from structure s. |
|
20 ## Return s if s is not a struct. Any better behavior? |
|
21 ## |
|
22 ## For m****b compatibility and flexibility. |
|
23 ## |
|
24 ## Basically, does a 'filtering' copy of s. |
|
25 ## |
|
26 ## See also cmpstruct, fields, setfield, isstruct, getfield, isfield, |
|
27 ## catstruct and struct. |
|
28 ## |
|
29 |
|
30 ## Author: Etienne Grossmann <etienne@isr.ist.utl.pt> |
|
31 ## Last modified: January 2000 |
|
32 ## November 2000: Paul Kienzle <pkienzle@kienzle.powernet.co.uk> |
|
33 ## return error rather than trapping to keyboard |
|
34 |
|
35 function t = rmfield(s,...) |
|
36 if ! is_struct(s) , |
|
37 t = s ; |
|
38 return |
|
39 end |
|
40 va_start() ; |
|
41 rmf = ' ' ; |
|
42 nargin-- ; |
|
43 while nargin-- , |
|
44 tmp = va_arg() ; |
|
45 if ! isstr(tmp) , |
|
46 error('rmfield: called with non-string key'); |
|
47 else |
|
48 rmf = [rmf,tmp,' '] ; |
|
49 end |
|
50 end |
|
51 for [val, key] = s , |
|
52 if ! index(rmf,[' ',key,' ']) , % Check if key is wanted |
|
53 eval(['t.',key,'=val;']) ; % Copy |
|
54 end |
|
55 end |