Skip to content

Commit

Permalink
Table: add selectRows.m and selectColumns.m
Browse files Browse the repository at this point in the history
  • Loading branch information
dlegland committed Mar 26, 2021
1 parent 4cfc7c6 commit f29364f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
31 changes: 31 additions & 0 deletions matStats/@Table/selectColumns.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function res = selectColumns(obj, inds)
% Seelct a subset of the table based on columns indices.
%
% RES = selectColumns(TAB, INDS)
%
% Example
% tab = Table.read('fisherIris');
% tab2 = selectColumns(tab, 1:4);
% size(tab2)
% ans =
% 150 4
%
%
% See also
% selectRows

% ------
% Author: David Legland
% e-mail: [email protected]
% INRAE - BIA Research Unit - BIBS Platform (Nantes)
% Created: 2021-03-26, using Matlab 9.8.0.1323502 (R2020a)
% Copyright 2021 INRAE.

newData = obj.Data(:, inds);
colNames = {};
if ~isempty(obj.ColNames)
colNames = obj.ColNames(inds);
end

% transform data
res = Table(newData, 'ColNames', colNames, 'Parent', obj);
31 changes: 31 additions & 0 deletions matStats/@Table/selectRows.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function res = selectRows(obj, inds)
% Seelct a subset of the table based on row indices.
%
% RES = selectRows(TAB, INDS)
%
% Example
% tab = Table.read('fisherIris');
% tab2 = selectRows(tab, 1:5:150);
% size(tab2)
% ans =
% 30 5
%
% See also
% selectColumns
%

% ------
% Author: David Legland
% e-mail: [email protected]
% INRAE - BIA Research Unit - BIBS Platform (Nantes)
% Created: 2021-03-26, using Matlab 9.8.0.1323502 (R2020a)
% Copyright 2021 INRAE.

newData = obj.Data(inds, :);
rowNames = {};
if ~isempty(obj.RowNames)
rowNames = obj.RowNames(inds);
end

% transform data
res = Table(newData, 'RowNames', rowNames, 'Parent', obj);

0 comments on commit f29364f

Please sign in to comment.