Line | |
---|
1 | %GETMETA retrieve metadata in a dataset by key names |
---|
2 | % |
---|
3 | % [VALUES,KEYS]=GETMETA(A,KEYS) |
---|
4 | % [VALUES,KEYS]=GETMETA(A) |
---|
5 | % |
---|
6 | % INPUT |
---|
7 | % A input dataset with meta structure (see MAKEMETA) |
---|
8 | % KEYS key (string) or a cell array of keys (optional) |
---|
9 | % |
---|
10 | % OUTPUT |
---|
11 | % VALUES values to be returned. Multiple values are returned in |
---|
12 | % a cell array. |
---|
13 | % KEYS a cell-array with all keys |
---|
14 | % |
---|
15 | % DESCRIPTION |
---|
16 | % Retrieve values for the given keys. If no keys are specified, |
---|
17 | % all values are returned. |
---|
18 | % |
---|
19 | % SEE ALSO |
---|
20 | % REMOVEMETA, GETMETA, SETMETA |
---|
21 | |
---|
22 | % $Id: getmeta.m,v 1.2 2005/05/02 14:10:08 pavel Exp $ |
---|
23 | |
---|
24 | function [out,keys]=getmeta(a,inkeys) |
---|
25 | |
---|
26 | isvalidmeta(a); |
---|
27 | |
---|
28 | if ~exist('inkeys','var') |
---|
29 | out=a.user.meta.values; |
---|
30 | if nargout==2, keys=a.user.meta.keys; end |
---|
31 | return |
---|
32 | end |
---|
33 | |
---|
34 | u=a.user; |
---|
35 | keys=u.meta.keys; |
---|
36 | values=u.meta.values; |
---|
37 | |
---|
38 | if ischar(inkeys) |
---|
39 | inkeys={inkeys}; % turn it into cell array |
---|
40 | end |
---|
41 | if ~iscell(inkeys) |
---|
42 | error('name or a cell array of names expected as keys') |
---|
43 | end |
---|
44 | % we know inkeys is a cell array |
---|
45 | out={}; |
---|
46 | for i=1:length(inkeys) |
---|
47 | ind=strcmp(a.user.meta.keys,inkeys{i}); |
---|
48 | if sum(ind)==0 |
---|
49 | error(['key ''' inkeys{i} ''' not defined!']); |
---|
50 | end |
---|
51 | ind=find(ind); |
---|
52 | out{i}=values{ind}; |
---|
53 | end |
---|
54 | |
---|
55 | if length(out)==1 |
---|
56 | out=out{1}; |
---|
57 | end |
---|
58 | |
---|
59 | return |
---|
Note: See
TracBrowser
for help on using the repository browser.