Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ans = integers(str)
- ans = [];
- h = "";
- flag = 0;
- i = 1;
- settlers = [' ', ',', ';'];
- while (i <= length(str))
- if ((str(i) >= '0') && (str(i) <= '9'))
- if ((flag == 1) || (i == 1))
- h = [h str(i)];
- flag = 1;
- elseif ((flag == 0) && (ismember(str(i-1), settlers)))
- h = [h str(i)];
- flag = 1;
- else
- flag = 0;
- h = "";
- end
- elseif ((ismember(str(i), settlers)) && (length(h) > 0) && (flag == 1))
- flag = 0;
- ans = [ans; str2num(h)];
- h = "";
- else
- flag = 0;
- h = "";
- end
- i+=1;
- end
- if (length(h) > 0)
- ans = [ans; str2num(h)];
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement