source: prextra/removeilab.m @ 33

Last change on this file since 33 was 5, checked in by bduin, 14 years ago
File size: 1.7 KB
Line 
1%REMOVEILAB remove named identifier columns
2%
3%   B=REMOVEILAB(A,REF)
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% OUTPUT
10%    B     output dataset
11%
12% DESCRIPTION
13% This cunction removes named identifiers (both names and per-example
14% values) from a ilab-enabled dataset (see ENABLEILAB).  If no identifier
15% name or index is given (REF is empty), the named-identifier capability is
16% removed from the dataset.
17%
18% SEE ALSO
19% ENABLEILAB, REMOVEILAB, GETILAB, SETILAB, GETILABLIST
20
21% $Id: removeilab.m,v 1.2 2005/05/02 13:05:46 pavel Exp $
22
23function a=removeilab(a,ref)
24   
25    isvalidilab(a);
26
27    if ~exist('ref','var')
28        u=a.user;
29        u=rmfield(u,'ilab');
30        a.user=u;
31        prwarning(1,'ilab capability was removed from a dataset');
32        return
33    end
34   
35    u=a.user;
36   
37    % get the columns to be set
38    col=[];
39    if isnumeric(ref)
40        col=ref;   
41    else
42        if ischar(ref)
43            ref={ref}; % turn it into cell array
44        end
45        if ~iscell(ref)
46            error('numerical index, name or cell array of names expected')
47        end
48        % we know ref is a cell array
49        for i=1:length(ref)
50            ind=strcmp(a.user.ilab.names,ref{i});
51            if sum(ind)==0
52                error(['identifier label ''' ref{i} ''' not defined!']);
53            end
54            col=[col find(ind==1)];
55        end
56    end
57   
58    if max(col)>size(a.user.ilab.names,2)
59        error('index exceeds number of defined ident labels');
60    end
61
62    names=u.ilab.names;
63    ncol=sort(setdiff(1:length(a.user.ilab.names),col));
64    names=names(ncol);
65    u.ilab.names=names;
66    a.user=u;
67   
68    % update ident
69    ident=a.ident;
70    ident(:,col)=[];
71    a.ident=ident;
72   
73    return
Note: See TracBrowser for help on using the repository browser.