Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. function [VALID_VARS] = sanitize_var_names(VARS)
  2. %{
  3. sanitize_var_names(VARS)
  4.  
  5. This function takes VARS, a list of strings or character vectors
  6. you want to use as TABLE.Properties.VariableNames. Built-in methods
  7. then proceed to sanitize the list to ensure variables are unique,
  8. and valid MATLAB identifiers. The sanitization process flow...
  9.  
  10. 1. Whitespace characters are removed. If a whitespace character is
  11. followed by a lowercase letter, the letter is converted to the
  12. corresponding uppercase character.
  13.  
  14. 2. The character vectors are then checked to ensure only valid
  15. MATLAB characters (A–Z, a–z, 0–9, _ ) are being used. Any
  16. invalid character found will be replaced by an underscore.
  17.  
  18. 3. Determines if any duplicate strings exist, and appends an
  19. underscore and a number (e.g. 'var', 'var_1') to any duplicates.
  20.  
  21.  
  22. EXAMPLE
  23. ------------------------------------------------------------------
  24.  
  25. T = array2table(randi(6,6))
  26.  
  27. shitList = {'1var' '1var' ' 1var' 'my var' 'v#3' 'alpha and Ω'}
  28.  
  29. validList = matlab.lang.makeValidName(shitList)
  30.  
  31. validListNoDupes = matlab.lang.makeUniqueStrings(validList)
  32.  
  33. ------------------------------------------------------------------
  34. %}
  35.  
  36.  
  37.  
  38. VALID_VARS = matlab.lang.makeUniqueStrings(matlab.lang.makeValidName(VARS));
  39.  
  40.  
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement