-
Notifications
You must be signed in to change notification settings - Fork 2
/
dataset_vertcat_fill_vars.m
46 lines (41 loc) · 1.4 KB
/
dataset_vertcat_fill_vars.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function ds_out = dataset_vertcat_fill_vars( varargin )
% DATASET_VERTCAT_FILL_VARS - create a new dataset by vertically concatenating
% all input arguments, preserving all variables present in any input.
%
% FIXME - Deprecated. This function is being superseded by
% 'table_vertcat_fill_vars.m'
%
% ds_out has all variables present anywhere in input datasets. When an input
% dataset is missing an output variable, the variable is added and to the
% dataset and populated with NaN.
%
% USAGE
% ds_out = dataset_vertcat_fill_vars( ds1, ds2, ... );
%
% INPUTS
% variable; two or more dataset arrays
%
% OUTPUTS
% ds_out: dataset array; the concatenated input datasets with all
% variables filled as described above.
%
% SEE ALSO
% dataset
%
% author: Timothy W. Hilton, UNM, Feb 2012
warning( 'This function ( dataset_vertcat_fill_vars.m ) is deprecated' );
all_vars = varargin{1}.Properties.VarNames;
for i = 2:numel( varargin )
all_vars = union( all_vars, varargin{i}.Properties.VarNames );
end
for i = 1:numel( varargin )
new_vars = setdiff( all_vars, varargin{i}.Properties.VarNames );
for j = 1:numel( new_vars )
varargin{ i }.( new_vars{ j } ) = ...
repmat( NaN, ...
size( varargin{ i }, 1 ), 1 );
end
end
% now all datasets have the same variables
ds_out = vertcat( varargin{ : } );
save('data.mat')