-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpx.m
87 lines (73 loc) · 2.13 KB
/
helpx.m
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function warnings=helpx(func)
% Run the example in the help section of a function
% The help section starts with the line "% EXAMPLE"
string=blanks(80);
string=strrep(string,' ','=');
helptext = help(func);
if isempty(helptext)
warnings=['Function "',func,'" has no help section'];
return
end
%linesep = [1 regexp(helptext,'\n')]
htext=tokens_no2(helptext,'\n');
idx=strmatch('EXAMPLE',strtrim(htext));
if ~isempty(idx)
if length(idx) > 1
warnings=['Function "',func,'" has more than one EXAMPLE'];
else
label=['Example for "',func,'" '];
disp([label,string(1:80-length(label))])
hhh=htext(idx+1:end);
hhh=splice_continued_lines_no1(hhh);
try
for ii=1:length(hhh)
temp=[strtrim(hhh{ii}),' ']; % Add a blank so that empty lines are displayed
disp(temp)
pause(0) % Make sure that the preceeding "display" command is
% executed befor the result of "eval" is displayed
% if ~isempty(temp)
eval(temp,',');
% end
end
catch
% ple
% keyboard
end
if nargout > 0
warnings=' ';
end
end
else
warnings=['Function "',func,'" has no EXAMPLE'];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function htext=splice_continued_lines_no1(htext)
% Splice command lines that end in ...
for ii=length(htext)-1:-1:1
temp=deblank(htext{ii});
if length(temp) > 3
while strcmp(temp(end-2:end),'...')
temp=[temp(1:end-3),htext{ii+1}];
htext(ii+1)=[];
end
end
htext{ii}=temp;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function cstr=tokens_no2(str,sep)
linesep = [0 regexp(str,sep)];
ntokens=length(linesep)-1;
if ntokens < 1
cstr=[];
return
end
cstr=cell(length(linesep),1);
ik=0;
for ii=1:ntokens
temp=str(linesep(ii)+1:linesep(ii+1)-1);
if 1 %~isempty(temp)
ik=ik+1;
cstr{ik}=temp;
end
end
cstr(ik+1:end)=[];