|
| 1 | +function outputFiltered = readAndFilterLogfile(columnName, filterBy, varargin) |
| 2 | + % outputFiltered = readOutputFilter(filterHeader, filterContent, varargin) |
| 3 | + % |
| 4 | + % It will display in the command window the content of the `output.tsv' filtered by one element |
| 5 | + % of a target column. |
| 6 | + % |
| 7 | + % DEPENDENCIES: |
| 8 | + % - bids_matlab (from CPP_BIDS) |
| 9 | + % |
| 10 | + % INPUT: |
| 11 | + % |
| 12 | + % - columnName: string, the header of the column where the content of insterest is stored |
| 13 | + % (e.g., for 'trigger' will be 'trial type') |
| 14 | + % - filterBy: string, the content of the column you want to filter out. It can take just |
| 15 | + % part of the content name (e.g., you want to display the triggers and you have |
| 16 | + % 'trigger_motion' and 'trigger_static', 'trigger' as input will do) |
| 17 | + % - varargin: either cfg (to display the last run output) or the file path as string |
| 18 | + % |
| 19 | + % OUTPUT: |
| 20 | + % |
| 21 | + % - outputFiltered: dataset with only the specified content, to see it in the command window |
| 22 | + % use display(outputFiltered) |
| 23 | + |
| 24 | + % Checke if input is cfg or the file path |
| 25 | + if ischar(varargin{1}) |
| 26 | + tsvFile = varargin{1}; |
| 27 | + elseif isstruct(varargin{1}) |
| 28 | + tsvFile = fullfile(varargin{1}.dir.outputSubject, ... |
| 29 | + varargin{1}.fileName.modality, ... |
| 30 | + varargin{1}.fileName.events); |
| 31 | + end |
| 32 | + |
| 33 | + % Check if the file exists |
| 34 | + if ~exist(tsvFile, 'file') |
| 35 | + error([newline 'Input file does not exist']); |
| 36 | + end |
| 37 | + |
| 38 | + % Read the the tsv file and store each column in a field of `output` structure |
| 39 | + output = bids.util.tsvread(tsvFile); |
| 40 | + |
| 41 | + % Get the index of the target contentent to filter and display |
| 42 | + filterIdx = find(strncmp(output.(columnName), filterBy, length(filterBy))); |
| 43 | + |
| 44 | + % Convert the structure to dataset |
| 45 | + outputDataset = struct2dataset(output); |
| 46 | + |
| 47 | + % Get the dataset with the content of intereset |
| 48 | + outputFiltered = outputDataset(filterIdx, :); |
| 49 | + |
| 50 | +end |
0 commit comments