shared-snippets/matlab/catalog/eliminateEmptyValues.m

43 lines
1.4 KiB
Mathematica
Raw Normal View History

2024-08-28 17:22:21 +02:00
%
% -----------------
% Copyright © 2019 ACK Cyfronet AGH, Poland.
%
% This work was partially funded by EPOS Project funded in frame of PL-POIR4.2
% --------------
%
function varargout = eliminateEmptyValues(varargin)
2024-08-29 13:11:12 +02:00
% ELIMINATEEMPTYVALUES Removes empty values from input columns
%
% [out1, out2, ...] = ELIMINATEEMPTYVALUES(in1, in2, ...) removes empty
% or NaN values from the input columns. The function takes a variable
% number of input arguments and returns the corresponding output columns
% without empty or NaN values. The inputs can be numeric arrays or cell
% arrays, and the function will remove entries that are empty in any of
% the input columns.
%
% This function is designed to work with catalog objects. For more
% information about the catalog format, refer to the documentation:
% https://docs.cyfronet.pl/display/ISDOC/Catalog+-+description
%
2024-08-29 13:11:12 +02:00
% Example:
% [a, b] = eliminateEmptyValues([1, NaN, 3], {'A', '', 'C'});
% % Result: a = [1, 3], b = {'A', 'C'}
%
2024-08-28 17:22:21 +02:00
if isempty(varargin)
return;
end
indexes = 1:length(varargin{1});
for i = 1:length(varargin)
column = varargin{i};
if isnumeric(column)
indexes = intersect(indexes, find(~isnan(column)));
elseif iscell(column)
indexes = intersect(indexes, find(~cellfun(@isempty, column)));
end
end
for i = 1:length(varargin)
varargout{i} = varargin{i}(indexes);
end
2024-08-29 13:11:12 +02:00
end