How to refer to a previous timestep in a matrix?

5 visualizzazioni (ultimi 30 giorni)
Johanna
Johanna il 9 Apr 2014
Commentato: Johanna il 9 Apr 2014
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

Risposte (1)

Walter Roberson
Walter Roberson il 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;

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by