annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_table_modify.m @ 0:cc4b1211e677 tip

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