source: prextra/getilab.m @ 113

Last change on this file since 113 was 5, checked in by bduin, 14 years ago
File size: 4.3 KB
Line 
1%GETILAB retrieve identifier values given identifier names or indices
2%
3%   LABS=GETILAB(A,REF,J)
4%
5% INPUT
6%    A      input dataset with ilab structure (see ENABLEILAB)
7%    REF    name, cell array with names or numerical indices of
8%           identifier columns
9%    J      indices specifying examples to be considered (optional)
10%
11% OUTPUT
12%    VALUES identifier values. If all identifiers are numerical, matrix is
13%           returned, otherwise cell array.
14%
15% DESCRIPTION
16% GETILAB returns values of identifiers, specified by names or numerical
17% indices. This function requires that the dataset supports
18% named-identifiers (see ENABLEILAB). Optional vector J specifies subset
19% of examples to be considered.
20%
21% SEE ALSO
22% ENABLEILAB, REMOVEILAB, GETILAB, SETILAB, GETILABLIST
23
24% $Id: getilab.m,v 1.4 2005/05/03 13:00:39 serguei Exp $
25
26function labs=getilab(a,ref,J)
27
28  isvalidilab(a);                                                   
29                                                                     
30  if ~exist('ref','var') | (exist('ref','var') & isempty(ref))       
31    % retrieve all identifiers                                       
32    ref=1:length(a.user.ilab.names);                                 
33  end                                                               
34                                                                     
35  if ~exist('J','var')                                               
36    J=1:size(a,1);                                                   
37  end                                                               
38                                                                     
39  % get the column to be returned                                   
40                                                                     
41  col=[];                                                           
42  if isnumeric(ref)                                                 
43    col=ref;                                                         
44  else                                                               
45    if ischar(ref)                                                   
46      ref={ref}; % turn it into cell array                           
47    end                                                             
48    if ~iscell(ref)                                                 
49      error('numerical index, name or cell array of names expected')
50    end                                                             
51    % we know ref is a cell array                                   
52    for i=1:length(ref)                                             
53      ind=strcmp(a.user.ilab.names,ref{i});                         
54      if sum(ind)==0                                                 
55        error(['identifier label ''' ref{i} ''' not defined!']);     
56      end                                                           
57      col=[col find(ind==1)];                                       
58    end                                                             
59  end                                                               
60                                                                     
61  if max(col)>size(a.user.ilab.names,2)                             
62    error('index exceeds number of defined ident labels');           
63  end                                                               
64                                                                     
65  % retrieve ident labels                                           
66  labs=a.ident(J,col);                                               
67  % if possible, convert the ilabs into numerical output             
68  try                                                               
69    labs = cell2mat(labs);                                           
70    % check if the cell array contained single objects               
71    if any(size(labs) ~= [length(J), length(col)]);                 
72      labs = a.ident(J,col);                                         
73    end                                                             
74  catch                                                             
75  end                                                               
76                                                                     
77  return                                                             
Note: See TracBrowser for help on using the repository browser.