diff --git a/matlab/catalog/eliminateEmptyValues.m b/matlab/catalog/eliminateEmptyValues.m index 1bc2a6c..fe24199 100644 --- a/matlab/catalog/eliminateEmptyValues.m +++ b/matlab/catalog/eliminateEmptyValues.m @@ -6,6 +6,20 @@ % -------------- % function varargout = eliminateEmptyValues(varargin) +% 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. +% +% Example: +% [a, b] = eliminateEmptyValues([1, NaN, 3], {'A', '', 'C'}); +% % Result: a = [1, 3], b = {'A', 'C'} +% + if isempty(varargin) return; end @@ -21,4 +35,4 @@ function varargout = eliminateEmptyValues(varargin) for i = 1:length(varargin) varargout{i} = varargin{i}(indexes); end -end \ No newline at end of file +end diff --git a/matlab/catalog/extractColumns.m b/matlab/catalog/extractColumns.m index c3149a7..8bc90ec 100644 --- a/matlab/catalog/extractColumns.m +++ b/matlab/catalog/extractColumns.m @@ -6,14 +6,36 @@ % -------------- % function [varargout] = extractColumns(catalog, varargin) - for i=1:length(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. +% +% 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) - for c=1:length(catalog) +% 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. + + for c = 1:length(catalog) if strcmp(catalog(c).field, colName) column = catalog(c).val; break; @@ -22,4 +44,4 @@ function column = findColumn(catalog, colName) if exist('column') ~= 1 error('no column named %s', colName); end -end \ No newline at end of file +end diff --git a/matlab/catalog/findCatalogColumn.m b/matlab/catalog/findCatalogColumn.m index 0b9c974..00926d3 100644 --- a/matlab/catalog/findCatalogColumn.m +++ b/matlab/catalog/findCatalogColumn.m @@ -3,11 +3,25 @@ % Copyright © 2022 ACK Cyfronet AGH, Poland. % -------------- % -% Returns index of the column with the specified colName within the given catalog -% -% TODO use this function in extractColumns.m function columnIdx = findCatalogColumn(catalog, colName) - for c=1:length(catalog) +% FINDCATALOGCOLUMN Find the index of a column in a catalog +% +% columnIdx = FINDCATALOGCOLUMN(catalog, colName) returns the index of +% the column with the specified name within the given catalog structure. +% The catalog is expected to be an array of structures where each +% structure has a 'field' representing the column name. +% +% Example: +% catalog(1).field = 'ID'; catalog(2).field = 'Time'; +% idx = findCatalogColumn(catalog, 'Time'); +% % Result: idx = 2 +% +% Note: This function is intended to be used in conjunction with other +% catalog processing functions. +% +% See also: EXTRACTCOLUMNS. + + for c = 1:length(catalog) if strcmp(catalog(c).field, colName) columnIdx = c; break; @@ -16,4 +30,4 @@ function columnIdx = findCatalogColumn(catalog, colName) if exist('columnIdx') ~= 1 error('no column named %s', colName); end -end \ No newline at end of file +end diff --git a/matlab/catalog/sortByTime.m b/matlab/catalog/sortByTime.m index 47954e4..c077538 100644 --- a/matlab/catalog/sortByTime.m +++ b/matlab/catalog/sortByTime.m @@ -4,12 +4,28 @@ % ----------------- % function [sortedCatalog] = sortByTime(catalog) +% SORTBYTIME Sorts a catalog structure by the 'Time' column +% +% sortedCatalog = SORTBYTIME(catalog) sorts the given catalog structure +% based on the values in the 'Time' column. The catalog is expected to be +% an array of structures where each structure has fields 'field' and +% 'val'. The function rearranges the catalog entries in ascending order +% of time. +% +% Example: +% catalog(1).field = 'ID'; catalog(1).val = [3, 2, 1]; +% catalog(2).field = 'Time'; catalog(2).val = [300, 200, 100]; +% sortedCatalog = sortByTime(catalog); +% % Result: sortedCatalog(2).val = [100, 200, 300] +% +% See also: FINDCATALOGCOLUMN, SORTROWS. + timeColIndex = find(strcmp('Time', {catalog.field})); if ~isempty(timeColIndex) [~, sortedIndexes] = sortrows(catalog(timeColIndex).val); - for i=1:length(catalog) + for i = 1:length(catalog) catalog(i).val = catalog(i).val(sortedIndexes); end end sortedCatalog = catalog; -end \ No newline at end of file +end diff --git a/matlab/unitutils/wavecut.m b/matlab/unitutils/wavecut.m index 33e7274..1491783 100644 --- a/matlab/unitutils/wavecut.m +++ b/matlab/unitutils/wavecut.m @@ -4,7 +4,20 @@ % ----------------- % function [wc]=wavecut(wf,startp,endp) - +% WAVECUT Extracts a segment of a waveform +% +% [WC] = WAVECUT(WF, STARTP, ENDP) extracts a segment of the waveform WF +% starting at position STARTP and ending at position ENDP. The input +% waveform WF is assumed to be a vector. STARTP and ENDP should be +% numeric values indicating the start and end positions of the desired +% segment. +% +% Example: +% wf = sin(0:0.01:2*pi); +% segment = wavecut(wf, 50, 150); +% plot(segment); +% +% See also: other functions that process waveforms. wc=wf(round(startp):round(endp)); end \ No newline at end of file