wolffd@0: function sT = som_table_modify(sT,action,arg1,arg2,arg3) wolffd@0: wolffd@0: %SOM_TABLE_MODIFY Modify table: add or remove columns or rows. wolffd@0: % wolffd@0: % sTable = som_table_modify(sTable,action,arg1,[arg2],[arg3]) wolffd@0: % wolffd@0: % Input and output arguments ([]'s are optional): wolffd@0: % sTable (struct) table struct wolffd@0: % action (string) action id (see below). wolffd@0: % arg1 (varies) Depending on action, 1 to 3 arguments wolffd@0: % [arg2] (varies) are needed. See below. wolffd@0: % [arg3] (varies) wolffd@0: % wolffd@0: % sTable (struct) the modified table struct wolffd@0: % wolffd@0: % Actions and their arguments: wolffd@0: % 'addcol' Add one or several new columns. wolffd@0: % arg1 (cell array) new values wolffd@0: % (char) new values (a single column can be given) wolffd@0: % (matrix) new values wolffd@0: % arg2 (cell array) new headers wolffd@0: % arg3 (scalar) at which position the new columns wolffd@0: % should be inserted (at the end by default) wolffd@0: % 'addrow' Add one or several new rows. wolffd@0: % arg1 (cell array) new values wolffd@0: % (char) new values (a single row can be given) wolffd@0: % (matrix) new values wolffd@0: % arg2 (scalar) at which position the new rows wolffd@0: % should be inserted (at the end by default) wolffd@0: % 'removecol' Remove one or several columns. wolffd@0: % arg1 (vector) indeces of columns to be removed wolffd@0: % 'removerow' Remove one or several rows. wolffd@0: % arg1 (vector) indeces of rows to be removed wolffd@0: % wolffd@0: % See also SOM_TABLE_STRUCT, SOM_TABLE_PRINT. wolffd@0: wolffd@0: % Contributed to SOM Toolbox 2.0, January 4th, 2002 by Juha Vesanto wolffd@0: % Copyright (c) by Juha Vesanto wolffd@0: % http://www.cis.hut.fi/projects/somtoolbox/ wolffd@0: wolffd@0: % Version 2.0beta juuso 040102 wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: [nrT,ncT] = size(sT.values); wolffd@0: wolffd@0: switch action, wolffd@0: case 'addcol', wolffd@0: values = arg1; wolffd@0: if ischar(values), values = cellstr(values); end wolffd@0: if isnumeric(values), values = num2cell(values); end wolffd@0: spans = ones([size(values) 2]); wolffd@0: [nr,nc] = size(values); wolffd@0: if nargin<4, header = cell(1,nc); header(:) = {''}; else header = arg2; end wolffd@0: if ischar(header), header = cellstr(header); end wolffd@0: if nargin<5, where = ncT+1; else where = arg3; end wolffd@0: if nrT ~= nr, wolffd@0: error('Mismatch between sizes of given table and additional columns') wolffd@0: else wolffd@0: sT.headers = [sT.headers(:,1:where-1), header, sT.headers(:,where:end)]; wolffd@0: sT.values = [sT.values(:,1:where-1), values, sT.values(:,where:end)]; wolffd@0: sT.span = [sT.span(:,1:where-1,:), spans, sT.span(:,where:end,:)]; wolffd@0: end wolffd@0: case 'addrow', wolffd@0: values = arg1; wolffd@0: if ischar(values), values = cellstr(values); end wolffd@0: if isnumeric(values), values = num2cell(values); end wolffd@0: [nr,nc] = size(values); wolffd@0: spans = ones([size(values) 2]); wolffd@0: if nargin<4, where = nrT+1; else where = arg2; end wolffd@0: if ncT ~= nc, wolffd@0: error('Mismatch between sizes of given table and additional rows') wolffd@0: else wolffd@0: sT.values = [sT.values(1:where-1,:); values; sT.values(where:end,:)]; wolffd@0: sT.span = [sT.span(1:where-1,:,:); spans; sT.span(where:end,:,:)]; wolffd@0: end wolffd@0: case 'removecol', wolffd@0: where = setdiff(1:ncT,arg1); wolffd@0: sT.values = sT.values(:,where); wolffd@0: sT.headers = sT.headers(:,where); wolffd@0: sT.span = sT.span(:,where,:); wolffd@0: case 'removerow', wolffd@0: where = setdiff(1:nrT,arg1); wolffd@0: sT.values = sT.values(where,:); wolffd@0: sT.headers = sT.headers(where,:); wolffd@0: sT.span = sT.span(where,:,:); wolffd@0: end wolffd@0: wolffd@0: return; wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%