source: prextra/removemeta.m @ 133

Last change on this file since 133 was 5, checked in by bduin, 14 years ago
File size: 1.2 KB
RevLine 
[5]1%REMOVEMETA remove key-value pairs
2%
3%   B=REMOVEMETA(A,KEYS)
4%
5% INPUT
6%    A     input dataset with meta structure (see ENABLEMETA)
7%    KEYS  key (string) or a cell array with keys
8%
9% OUTPUT
10%    B     output dataset
11%
12% DESCRIPTION
13% Remove the key-value pairs specified by the keys. If no keys are
14% specified, the meta facility is removed from the dataset.
15%
16% SEE ALSO
17% REMOVEMETA, GETMETA, SETMETA
18
19% $Id: removemeta.m,v 1.3 2005/05/02 14:12:10 pavel Exp $
20
21function a=removemeta(a,inkeys)
22   
23    isvalidmeta(a);
24
25    u=a.user;   
26    if ~exist('inkeys','var')
27        u=rmfield(u,'meta');
28        a.user=u;
29        prwarning(1,'meta capability was removed from a dataset');
30        return
31    end
32       
33    keys=u.meta.keys;
34    values=u.meta.values;   
35   
36    if ischar(inkeys)
37        inkeys={inkeys}; % turn it into cell array
38    end
39    if ~iscell(inkeys)
40        error('name or a cell array of names expected as keys')
41    end
42    % we know inkeys is a cell array
43    for i=1:length(inkeys)
44        ind=strcmp(a.user.meta.keys,inkeys{i});
45        if sum(ind)==0
46            error(['key ''' inkeys{i} ''' not defined!']);
47        end
48        ind=find(ind);
49        keys(ind)=[];
50        values(ind)=[];
51    end
52   
53    u.meta.keys=keys;
54    u.meta.values=values;
55    a.user=u;
56   
57    return
Note: See TracBrowser for help on using the repository browser.