intfromstr_dot.m
上传用户:jspk663
上传日期:2013-08-19
资源大小:232k
文件大小:1k
- function s=intfromstr_dot(answer)
- %Distill integers from a string,dot as -1;
- p=1;q=1;k=0;v=0;i=1;
- l=length(answer);
- while i<=l-1
- if isnumber(answer(i)) & ~isnumber(answer(i+1))
- k=k+1;
- s(k)=str2num(answer(i));
- i=i+1;
-
- elseif isnumber(answer(i)) & isnumber(answer(i+1))
- j=i;
- while j<=l & isnumber(answer(j));
- t(p)=str2num(answer(j));
- p=p+1;
- j=j+1;
- end
- for p=length(t):-1:1
- v=v+t(q)*10^(p-1);
- q=q+1;
- end
- k=k+1;
- s(k)=v;
- i=i+length(t);
- p=1;q=1;v=0;t=0;
- elseif answer(i)=='.'
- k=k+1;
- s(k)=-1;
- i=i+1;
- while answer(i)=='.' & i<l
- i=i+1;
- end
-
- else
- i=i+1;
- end
-
- end
- if i==l
- if isnumber(answer(i))
- k=k+1;
- s(k)=str2num(answer(i));
- elseif answer(i)=='.' & l>1 & answer(i-1)~='.'
- k=k+1;
- s(k)=-1;
- elseif answer(i)=='.' & l==1
- k=k+1;
- s(k)=-1;
- end
- end