forked from jemoster/aerospace-design-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
findValue.m
29 lines (28 loc) · 1.08 KB
/
findValue.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
function [value, line] = findValue(file, name, area)
%Check each line in the search area
for line=area(1):area(2)
%Get a line
str = char(file(line));
%Search the line for the keyword
header = regexp(str, name);
%If we found something
if(~isempty(header))
%Get the remainder of the string after the keyword
str = str(header+length(name):length(str));
%Split the string everytime a space is found
s2 = regexp(str, ' ', 'split');
%For each element
for j = 1:length(s2)
if(~isempty(s2{j})) % && ~strcmp(s2(j),'=')
value = str2double(char(s2(j)));
if ~isnan(value)
return;
end
end
end
warning(strcat('Could not find value for variable: ', name));
end
end
warning(strcat('Did not variable in file: ', name));
value = 0;
end