wolffd@0
|
1 function sT = som_table_modify(sT,action,arg1,arg2,arg3)
|
wolffd@0
|
2
|
wolffd@0
|
3 %SOM_TABLE_MODIFY Modify table: add or remove columns or rows.
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % sTable = som_table_modify(sTable,action,arg1,[arg2],[arg3])
|
wolffd@0
|
6 %
|
wolffd@0
|
7 % Input and output arguments ([]'s are optional):
|
wolffd@0
|
8 % sTable (struct) table struct
|
wolffd@0
|
9 % action (string) action id (see below).
|
wolffd@0
|
10 % arg1 (varies) Depending on action, 1 to 3 arguments
|
wolffd@0
|
11 % [arg2] (varies) are needed. See below.
|
wolffd@0
|
12 % [arg3] (varies)
|
wolffd@0
|
13 %
|
wolffd@0
|
14 % sTable (struct) the modified table struct
|
wolffd@0
|
15 %
|
wolffd@0
|
16 % Actions and their arguments:
|
wolffd@0
|
17 % 'addcol' Add one or several new columns.
|
wolffd@0
|
18 % arg1 (cell array) new values
|
wolffd@0
|
19 % (char) new values (a single column can be given)
|
wolffd@0
|
20 % (matrix) new values
|
wolffd@0
|
21 % arg2 (cell array) new headers
|
wolffd@0
|
22 % arg3 (scalar) at which position the new columns
|
wolffd@0
|
23 % should be inserted (at the end by default)
|
wolffd@0
|
24 % 'addrow' Add one or several new rows.
|
wolffd@0
|
25 % arg1 (cell array) new values
|
wolffd@0
|
26 % (char) new values (a single row can be given)
|
wolffd@0
|
27 % (matrix) new values
|
wolffd@0
|
28 % arg2 (scalar) at which position the new rows
|
wolffd@0
|
29 % should be inserted (at the end by default)
|
wolffd@0
|
30 % 'removecol' Remove one or several columns.
|
wolffd@0
|
31 % arg1 (vector) indeces of columns to be removed
|
wolffd@0
|
32 % 'removerow' Remove one or several rows.
|
wolffd@0
|
33 % arg1 (vector) indeces of rows to be removed
|
wolffd@0
|
34 %
|
wolffd@0
|
35 % See also SOM_TABLE_STRUCT, SOM_TABLE_PRINT.
|
wolffd@0
|
36
|
wolffd@0
|
37 % Contributed to SOM Toolbox 2.0, January 4th, 2002 by Juha Vesanto
|
wolffd@0
|
38 % Copyright (c) by Juha Vesanto
|
wolffd@0
|
39 % http://www.cis.hut.fi/projects/somtoolbox/
|
wolffd@0
|
40
|
wolffd@0
|
41 % Version 2.0beta juuso 040102
|
wolffd@0
|
42
|
wolffd@0
|
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
44
|
wolffd@0
|
45 [nrT,ncT] = size(sT.values);
|
wolffd@0
|
46
|
wolffd@0
|
47 switch action,
|
wolffd@0
|
48 case 'addcol',
|
wolffd@0
|
49 values = arg1;
|
wolffd@0
|
50 if ischar(values), values = cellstr(values); end
|
wolffd@0
|
51 if isnumeric(values), values = num2cell(values); end
|
wolffd@0
|
52 spans = ones([size(values) 2]);
|
wolffd@0
|
53 [nr,nc] = size(values);
|
wolffd@0
|
54 if nargin<4, header = cell(1,nc); header(:) = {''}; else header = arg2; end
|
wolffd@0
|
55 if ischar(header), header = cellstr(header); end
|
wolffd@0
|
56 if nargin<5, where = ncT+1; else where = arg3; end
|
wolffd@0
|
57 if nrT ~= nr,
|
wolffd@0
|
58 error('Mismatch between sizes of given table and additional columns')
|
wolffd@0
|
59 else
|
wolffd@0
|
60 sT.headers = [sT.headers(:,1:where-1), header, sT.headers(:,where:end)];
|
wolffd@0
|
61 sT.values = [sT.values(:,1:where-1), values, sT.values(:,where:end)];
|
wolffd@0
|
62 sT.span = [sT.span(:,1:where-1,:), spans, sT.span(:,where:end,:)];
|
wolffd@0
|
63 end
|
wolffd@0
|
64 case 'addrow',
|
wolffd@0
|
65 values = arg1;
|
wolffd@0
|
66 if ischar(values), values = cellstr(values); end
|
wolffd@0
|
67 if isnumeric(values), values = num2cell(values); end
|
wolffd@0
|
68 [nr,nc] = size(values);
|
wolffd@0
|
69 spans = ones([size(values) 2]);
|
wolffd@0
|
70 if nargin<4, where = nrT+1; else where = arg2; end
|
wolffd@0
|
71 if ncT ~= nc,
|
wolffd@0
|
72 error('Mismatch between sizes of given table and additional rows')
|
wolffd@0
|
73 else
|
wolffd@0
|
74 sT.values = [sT.values(1:where-1,:); values; sT.values(where:end,:)];
|
wolffd@0
|
75 sT.span = [sT.span(1:where-1,:,:); spans; sT.span(where:end,:,:)];
|
wolffd@0
|
76 end
|
wolffd@0
|
77 case 'removecol',
|
wolffd@0
|
78 where = setdiff(1:ncT,arg1);
|
wolffd@0
|
79 sT.values = sT.values(:,where);
|
wolffd@0
|
80 sT.headers = sT.headers(:,where);
|
wolffd@0
|
81 sT.span = sT.span(:,where,:);
|
wolffd@0
|
82 case 'removerow',
|
wolffd@0
|
83 where = setdiff(1:nrT,arg1);
|
wolffd@0
|
84 sT.values = sT.values(where,:);
|
wolffd@0
|
85 sT.headers = sT.headers(where,:);
|
wolffd@0
|
86 sT.span = sT.span(where,:,:);
|
wolffd@0
|
87 end
|
wolffd@0
|
88
|
wolffd@0
|
89 return;
|
wolffd@0
|
90
|
wolffd@0
|
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|