source: prextra/setmeta.m @ 82

Last change on this file since 82 was 5, checked in by bduin, 14 years ago
File size: 1.2 KB
Line 
1%SETMETA add/update key-value pair(s) to a dataset
2%
3%   B=SETMETA(A,KEYS,VALUES)
4%
5% INPUT
6%    A       input dataset with meta structure (see MAKEMETA)
7%    KEYS    string key or a cell-array with key names
8%    VALUES  key-specific values. If more keys are defined, VALUES
9%            must be stored in a cell-array
10%
11% OUTPUT
12%    B     output dataset
13%
14% DESCRIPTION
15% This function sets the key-value pair(s) in a user field of a dataset.
16%
17% SEE ALSO
18% REMOVEMETA, GETMETA, SETMETA
19
20function a=setmeta(a,inkeys,invalues)
21   
22    isvalidmeta(a);
23
24    u=a.user;
25
26    if ischar(inkeys), inkeys={inkeys}; end
27    if ~iscell(invalues), invalues={invalues}; end   
28
29    if ~iscell(inkeys) | ~iscell(invalues)
30        error('unsupported format of keys or values')
31    end
32    if length(inkeys)~=length(invalues)
33        error('keys and values to be set must have equal sizes');
34    end
35
36    % update meta in user
37    u=a.user;
38    for j=1:length(inkeys)
39        % is the key already defined?
40        ind=strcmp(u.meta.keys,inkeys{j});
41        if any(ind)
42            k=find(ind);
43            u.meta.keys{k}=inkeys{j};
44            u.meta.values{k}=invalues{j};
45        else % not found, add a new key-value
46            u.meta.keys{end+1}=inkeys{j};
47            u.meta.values{end+1}=invalues{j};
48        end     
49    end
50    a.user=u;
51   
52    return
Note: See TracBrowser for help on using the repository browser.