2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,15 +1,16 @@
% Is string numeric?
function out = is_str_numeric(s)
out = ~isempty(parse_float(s));
end
% copy from Octave version on this page
function r = isnum(a)
if ( isnumeric(a) )
r = 1;
else
o = str2num(a);
r = !isempty(o);
endif
end
% Returns the float (double) if true, empty array otherwise.
function f = parse_float(s)
[f_in_cell, pos] = textscan(s, '%f');
% Make sure there are no trailing chars. textscan(..) is greedy.
if pos == length(s)
f = f_in_cell{:};
else
f = [];
end
end
% tests
disp(isnum(123)) % 1
disp(isnum("123")) % 1
disp(isnum("foo123")) % 0
disp(isnum("123bar")) % 0
disp(isnum("3.1415")) % 1