How to refer to a previous timestep in a matrix?

5 vues (au cours des 30 derniers jours)
Johanna
Johanna le 9 Avr 2014
Commenté : Johanna le 9 Avr 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

Réponses (1)

Walter Roberson
Walter Roberson le 9 Avr 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;

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by