Hi,
It is the expected behaviour where MATLAB save the latest value in the workspace.
However, if you want to save all the values of the variables you can append the values in an array/matrix and access them accordingly.
Please refer to the following answers on how to append in the array:
- https://www.mathworks.com/matlabcentral/answers/283821-add-single-element-to-array-or-vector
- https://www.mathworks.com/matlabcentral/answers/87549-append-to-an-array
Hope this helps!!