source: prextra/setilab.m @ 5

Last change on this file since 5 was 5, checked in by bduin, 14 years ago
File size: 1.7 KB
RevLine 
[5]1%SETILAB set the values for the per-example named-identifiers in a dataset
2%
3%   B=SETILAB(A,REF,VALUES,J)
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%    VALUES  identifier values to be set. If all values are numerical,
10%            matrix may be supplied, otherwise a cell array.
11%    J       sample indices to be retrieved (optional)
12%
13% OUTPUT
14%    B       output dataset
15%
16% DESCRIPTION
17% SETILAB sets the values of identifiers, specified by names for all
18% examples in a dataset (or for a subset, given by example indices J).
19% VALUES may be a matrix, in case all values to be set are numerical, or
20% a cell array otherwise.
21%
22% SEE ALSO
23% ENABLEILAB, REMOVEILAB, GETILAB, SETILAB, GETILABLIST
24
25function a=setilab(a,ref,labs,J)
26   
27    isvalidilab(a);
28
29    if isempty(ref)
30        % replace all identifiers
31        ref=1:length(a.user.ilab.names);
32    end
33   
34    if ~exist('J','var')
35        J=1:size(a,1);
36    end
37   
38    % get the columns to be set
39    col=[];
40    if isnumeric(ref)
41        col=ref;   
42    else
43        if ischar(ref)
44            ref={ref}; % turn it into cell array
45        end
46        if ~iscell(ref)
47            error('numerical index, name or cell array of names expected')
48        end
49        % we know ref is a cell array
50        for i=1:length(ref)
51            ind=strcmp(a.user.ilab.names,ref{i});
52            if sum(ind)==0
53                error(['identifier label ''' ref{i} ''' not defined!']);
54            end
55            col=[col find(ind==1)];
56        end
57    end
58   
59    if max(col)>size(a.user.ilab.names,2)
60        error('index exceeds number of defined ident labels');
61    end
62 
63    if isnumeric(labs)
64        labs=num2cell(labs);
65    end
66   
67    % retrieve ident labels
68    temp=a.ident;
69    temp(J,col)=labs;
70    a.ident=temp;
71   
72    return
73   
Note: See TracBrowser for help on using the repository browser.