54 lines
1.8 KiB
Matlab
54 lines
1.8 KiB
Matlab
%
|
|
% -----------------
|
|
% Copyright © 2019 ACK Cyfronet AGH, Poland.
|
|
%
|
|
% This work was partially funded by EPOS Project funded in frame of PL-POIR4.2
|
|
% --------------
|
|
%
|
|
function [varargout] = extractColumns(catalog, varargin)
|
|
% EXTRACTCOLUMNS Extracts specified columns from a catalog structure
|
|
%
|
|
% [col1, col2, ...] = EXTRACTCOLUMNS(catalog, 'colName1', 'colName2', ...)
|
|
% extracts the columns with the specified names from the catalog
|
|
% structure. The catalog is expected to be an array of structures where
|
|
% each structure has fields 'field' and 'val'. The function returns the
|
|
% values of the requested columns.
|
|
%
|
|
% For more details on the catalog format, see:
|
|
% https://docs.cyfronet.pl/display/ISDOC/Catalog+-+description
|
|
%
|
|
% Example:
|
|
% catalog(1).field = 'ID'; catalog(1).val = [1, 2, 3];
|
|
% catalog(2).field = 'Time'; catalog(2).val = [100, 200, 300];
|
|
% [id, time] = extractColumns(catalog, 'ID', 'Time');
|
|
% % Result: id = [1, 2, 3], time = [100, 200, 300]
|
|
%
|
|
% See also: FINDCATALOGCOLUMN.
|
|
|
|
for i = 1:length(varargin)
|
|
colName = varargin{i};
|
|
varargout{i} = findColumn(catalog, colName);
|
|
end
|
|
end
|
|
|
|
function column = findColumn(catalog, colName)
|
|
% FINDCOLUMN Helper function to find the values of a column in a catalog
|
|
%
|
|
% column = FINDCOLUMN(catalog, colName) searches the catalog structure
|
|
% for the specified column name and returns its values. If the column
|
|
% does not exist, an error is thrown.
|
|
%
|
|
% Refer to the catalog documentation for further information:
|
|
% https://docs.cyfronet.pl/display/ISDOC/Catalog+-+description
|
|
|
|
for c = 1:length(catalog)
|
|
if strcmp(catalog(c).field, colName)
|
|
column = catalog(c).val;
|
|
break;
|
|
end
|
|
end
|
|
if exist('column') ~= 1
|
|
error('no column named %s', colName);
|
|
end
|
|
end
|