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