How to refer to a previous timestep in a matrix?

1 view (last 30 days)
I have several timesteps and a large matrix (lets call it old) I would like to replace the old matrix with an updated version containing the "old" from the previous timestep and another matrix called "new". I would like to do this for every row and column.
My problem is how to refer to the row and column in the previous timestep. How can I do that? The bolded part...
for t=2:481
for row=1:231;
for col=1:204;
old(row,col)= *old(t-1)* -new(row,col);
end
end
end

Answers (1)

Walter Roberson
Walter Roberson on 9 Apr 2014
old(row,col) = old(row,col) - new(row,col);
In the particular case you show, you can eliminate the loop and use
old(1:231, 1:204) = old(1:231, 1:204) - new(1:231, 1:204);
If those are the complete array limits rather than just part of the array, this can be recoded as
old = old - new;

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!