-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecuteTextInScript.m
More file actions
60 lines (52 loc) · 1.28 KB
/
ExecuteTextInScript.m
File metadata and controls
60 lines (52 loc) · 1.28 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function ExecuteTextInScript(theScript)
% Open file, read it, execute the text via eval
%
% Syntax:
% ExecuteTextInScript(theScript)
%
% Description
% This is mostly to test that if we have a string
% of Matlab code, we can execute it using eval.
%
% Inputs:
% theScript - String. Name of the script to execute (with the .m at the
% end).
%
% Outputs:
% None.
%
% Optional key/value pairs:
% None
%
% Examples are provided in the code.
%
% See also:
% ExecuteExamplesInScript
%
% History
% 01/16/18 dhb Wasting time on a train.
% Examples:
%{
ExecuteTextInScript('SimpleScript.m');
%}
%{
% Another example. This is here to help
% test function ExecuteExamplesInScript.
fprintf('Executing example ');
% More comment
fprintf('number two!\n');
%}
%{
This is a real block comment, and should not be executed as an example.
You can tell because it is not contiguous after the real examples above.
%}
% Open file
theFileH = fopen(theScript,'r');
theText = {char(fread(theFileH,'uint8=>char')')};
fclose(theFileH);
% Evaluate the text
eval(theText{1});
%{
And here is another real real block comment, that also should not be executed as an example.
You can tell because it is not contiguous after the real examples above.
%}