<p>I am trying to create a MATLAB class with a member variable that's being updated as a result of a method invocation, but when I try to change the property within the class it (apperently, from what I understood from MATLAB's memory management) creates a copy of the object and then modifies it, leaving the original object's property untouched.</p>

<pre><code>classdef testprop  
    properties  
        numRequests=0;  
    end  
    methods  
        function Request(this, val)  
            disp(val);  
            this.numRequests=this.numRequests+1;  
        end  
    end  
end  
</code></pre>

<p>.</p>

<pre><code>&gt;&gt; a=testprop;
&gt;&gt; a.Request(9);
&gt;&gt; a.Request(5);  
&gt;&gt; a.numRequests  

ans = 0  
</code></pre>

Using a Value (Vanilla) Class
When using a value class you need to tell Matlab to store a modified copy of the object to save the changes in the property value.  So,
```
```
>> a=testprop
>> a.Request(5); % will NOT change the value of a.numRequests.
5

>> a.Request(5) 
5

>> a.numRequests
ans = 
       0

>> a=a.Request; % However, this will work but as you it makes a copy of variable, a.
5

>> a=a.Request; 
5

>> a.numRequests
ans =
       2
```
```
As
Kamran
notes, this requires changing the definition of function
```
Request
```
to be
```
```
function this = Request(this, val)`
```
```
Using a Handle Class
If you inherit from the handle class, that is
```
```
classdef testprop < handle
```
```
then you can write,
```
```
>> a.Request(5);
>> a.Request(5);
>> a.numRequests
ans = 
       2
```
```
Note that this changes the behavior of the objects, see
the documentation
to learn the difference between a value class and a handle class.