intfromstr_dot.m
上传用户:jspk663
上传日期:2013-08-19
资源大小:232k
文件大小:1k
源码类别:

matlab例程

开发平台:

Matlab

  1. function s=intfromstr_dot(answer)
  2. %Distill integers from a string,dot as -1;
  3. p=1;q=1;k=0;v=0;i=1;
  4. l=length(answer);
  5. while i<=l-1
  6.     if  isnumber(answer(i)) & ~isnumber(answer(i+1))
  7.         k=k+1;
  8.         s(k)=str2num(answer(i));
  9.         i=i+1;
  10.         
  11.     elseif isnumber(answer(i)) & isnumber(answer(i+1))
  12.         j=i;
  13.         while j<=l & isnumber(answer(j));
  14.             t(p)=str2num(answer(j));
  15.             p=p+1;
  16.             j=j+1;
  17.         end
  18.         for p=length(t):-1:1
  19.             v=v+t(q)*10^(p-1);
  20.             q=q+1;
  21.         end
  22.         k=k+1;
  23.         s(k)=v;
  24.         i=i+length(t);
  25.         p=1;q=1;v=0;t=0;      
  26.     elseif answer(i)=='.'
  27.         k=k+1;
  28.         s(k)=-1;
  29.         i=i+1;
  30.         while answer(i)=='.' & i<l
  31.             i=i+1;
  32.         end          
  33.         
  34.     else
  35.         i=i+1;
  36.     end
  37.        
  38. end
  39. if i==l
  40.     if isnumber(answer(i))
  41.         k=k+1;
  42.         s(k)=str2num(answer(i));
  43.     elseif answer(i)=='.' & l>1 & answer(i-1)~='.'
  44.         k=k+1;
  45.         s(k)=-1;
  46.     elseif answer(i)=='.' & l==1
  47.         k=k+1;
  48.         s(k)=-1;
  49.     end
  50. end