title: MATLAB: Quickest Way To Convert Characters to A Custom Set Numbers and Back
body: <p>I'm looking for a quick way to convert a large character array of lowercase letters, spaces and periods into a set of integers and vice-versa in MATLAB. </p>
  
  <p>Usually I would use the double and char functions, but I would like to use a special set of integers to represent each letter (so that 'a' matches with '1', 'b' matches with '2'.... 'z' matches with 26, ' ' matches with 27, and '.' matches with 28)</p>
  
  <p>The current method that I have is:</p>
  
  <pre><code>text = 'quick brown fox jumps over dirty dog';
  alphabet ='abcdefghijklmnopqrstuvwxyz .';
  
  converted_text = double(text);
  converted_alphabet = double(alphabet);
  
  numbers = nan(28,1)
  
  for i = 1:28
       numbers(converted_text(i)==converted_alphabet(i)) = i;
  end
  
  newtext = nan(size(numbers))
  
  for i = 1:size(numbers,1)
     newtext(numbers==i) = alphabet(i)
  end
  </code></pre>
  
  <p>Unfortunately this takes quite a bit of time for large arrays, and I'm wondering if there is a quicker way to do this in MATLAB?</p>