-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetCode.m
More file actions
43 lines (39 loc) · 965 Bytes
/
getCode.m
File metadata and controls
43 lines (39 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function S = getCode(filename)
%% GETCODE Reads text from code file, excluding comment or whitespace lines
%% Syntax
% S = getCode(filename)
%
%
%% Description
% `S = getCode(filename)` creates a string by concatenating the lines from a
% script or function file, excluding lines of only whitespace or starting with a
% `%` character, and trimming whitespace on each line.
%
%
%% Examples
% getCode('getCode')
%
%
%% Input Arguments
% `filename - file name (string scalar | character vector)`
%
%
%% Output Arguments
% `S - file text (string scalar)`
%
%
%% See Also
% READLINES, REGEXP, JOIN, getFileHash
%
%
%% Authors
% Mehul Gajwani, Monash University, 2024
%
%
% get text
filetext = readlines(which(filename), ...
'WhitespaceRule', 'trim', 'EmptyLineRule', 'skip');
% remove lines that start with '%' character
idx = cell2mat(cellfun(@(x) isempty(x), regexp(filetext, "^\%"),'Uni',0));
S = join(filetext(idx), newline); % return
end