Add documentation for matlab files

This commit is contained in:
Mieszko Makuch 2024-08-29 13:11:12 +02:00
parent ee5a68f833
commit 221d8ba37a
5 changed files with 91 additions and 12 deletions

View File

@ -6,6 +6,20 @@
% -------------- % --------------
% %
function varargout = eliminateEmptyValues(varargin) 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) if isempty(varargin)
return; return;
end end

View File

@ -6,14 +6,36 @@
% -------------- % --------------
% %
function [varargout] = extractColumns(catalog, varargin) 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}; colName = varargin{i};
varargout{i} = findColumn(catalog, colName); varargout{i} = findColumn(catalog, colName);
end end
end end
function column = findColumn(catalog, colName) 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) if strcmp(catalog(c).field, colName)
column = catalog(c).val; column = catalog(c).val;
break; break;

View File

@ -3,11 +3,25 @@
% Copyright © 2022 ACK Cyfronet AGH, Poland. % 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) 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) if strcmp(catalog(c).field, colName)
columnIdx = c; columnIdx = c;
break; break;

View File

@ -4,10 +4,26 @@
% ----------------- % -----------------
% %
function [sortedCatalog] = sortByTime(catalog) 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})); timeColIndex = find(strcmp('Time', {catalog.field}));
if ~isempty(timeColIndex) if ~isempty(timeColIndex)
[~, sortedIndexes] = sortrows(catalog(timeColIndex).val); [~, sortedIndexes] = sortrows(catalog(timeColIndex).val);
for i=1:length(catalog) for i = 1:length(catalog)
catalog(i).val = catalog(i).val(sortedIndexes); catalog(i).val = catalog(i).val(sortedIndexes);
end end
end end

View File

@ -4,7 +4,20 @@
% ----------------- % -----------------
% %
function [wc]=wavecut(wf,startp,endp) 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)); wc=wf(round(startp):round(endp));
end end