mttFindEquationVariables.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. function [varlist,location] = mttFindEquationVariables(line)
  2. line = mttClipText(line) ;
  3. if isempty(line)
  4. namelist = [] ;
  5. location = [] ;
  6. else
  7. numbers = (line>=48 & line<=57) ;
  8. letters = (line>=65 & line<=90)|(line>=97 & line<=122) ;
  9. underscores = (line==95) ;
  10. dots = (line==46) ;
  11. apostrophes = (line==39) ;
  12. mask = (numbers|letters|underscores|dots|apostrophes) ;
  13. buffer = line ;
  14. buffer(~mask) = char(32*ones(1,sum(~mask))) ;
  15. next = 1 ;
  16. last = length(buffer) ;
  17. counter = 0 ;
  18. finding = any(mask) ;
  19. while finding
  20. i = min(find(~isspace(buffer(next:last))))+next-1 ;
  21. if isempty(i)
  22. finding = 0 ;
  23. else
  24. if i>last
  25. finding = 0 ;
  26. else
  27. if i==last
  28. j = last ;
  29. else
  30. j = min(find(isspace(buffer(i+1:last))))+i ;
  31. if isempty(j)
  32. j = last ;
  33. else
  34. j = j - 1 ;
  35. end
  36. end
  37. if ~mttIsNumericText(buffer(i:j))
  38. var_found = 1 ;
  39. if j<last
  40. jj = min(find(~isspace(line(j+1:last))))+j ;
  41. if line(jj)=='('
  42. var_found = 0 ;
  43. end
  44. end
  45. if var_found
  46. counter = counter + 1 ;
  47. varlist{counter} = buffer(i:j) ;
  48. location(counter) = i ;
  49. end
  50. end
  51. next = j + 1 ;
  52. finding = (next<last) & ~isempty(i) ;
  53. end
  54. end
  55. end
  56. end