title: Changing the elements of a matrix using a for loop in matlab
body: <p>I'm having a few issues getting MATLAB to do what I want.</p>
  
  <p>say I have a matrix <code>x = [1 2 3 4; 1 4 4 5; 6 4 1 4]</code></p>
  
  <p>I'm trying to write code that will go through the matrix and change each 4 to a 5, so it modifies the input matrix</p>
  
  <p>I've tried a few things:</p>
  
  <pre><code>while index &lt;= numel(x)
      if index == 4
          index = 5;
      end
      index = index + 1;
  end
  
  
  for item = x
      if item == 4
          item = 5;
      end
  end
  </code></pre>
  
  <p>the simplest thing i tried was</p>
  
  <pre><code>for item = x
      if item == 4
          item = 5;
      end
  end
  </code></pre>
  
  <p>i noticed by looking at the workspace that the value of item did indeed change but the value of x (the matrix) stayed the same.</p>
  
  <p>How do I get the output that i'm looking for?</p>