source: prextra/addilab.m @ 113

Last change on this file since 113 was 5, checked in by bduin, 14 years ago
File size: 1.4 KB
Line 
1%ADDILAB add named identifier to a dataset
2%
3%   B=ADDILAB(A,REF,LABS)
4%
5% INPUT
6%    A     input dataset with ilab structure (see MAKEILAB)
7%    REF   name, cell array with names or numerical indices of
8%          identifier columns
9%    LABS  identifiers to be set. If all identifiers are numerical,
10%          matrix may be supplied, otherwise a cell array.
11%
12% OUTPUT
13%    B     output dataset
14%
15% DESCRIPTION
16% This function adds one or more named identifiers to the dateset
17% and sets their per-example values. To be used, the named-identifier
18% facility must be enabled in a dataset (see ENABLEILAB).
19%
20% SEE ALSO
21% ENABLEILAB, REMOVEILAB, GETILAB, SETILAB, GETILABLIST
22
23% $Id: addilab.m,v 1.2 2005/05/02 13:05:46 pavel Exp $
24
25function a=addilab(a,name,labs)
26   
27    isvalidilab(a);
28
29    u=a.user;
30   
31    % is the name already defined?
32    ind=strcmp(u.ilab.names,name);
33    if any(ind)
34        error([name ' already defined in ilab!']);
35    else
36       
37        % check the validity of labs to be added
38        if length(labs)~=size(a,1)
39            length(labs)
40            error('wrong size of ident labels to be included!');
41        end
42
43%       labs=reshape(labs,size(a,1),1);
44       
45        if isnumeric(labs)
46            labs=num2cell(labs);
47        end
48       
49        if ~iscell(labs)
50            error('ident labels to include must be either cell array or numerical vector');
51        end
52       
53        % update ilab
54        u.ilab.names{end+1}=name;
55        a.user=u;
56        ident=a.ident;
57        ident(:,end+1)=labs;
58        a.ident=ident;
59       
60    end
61   
62    return
Note: See TracBrowser for help on using the repository browser.