How to refer to a previous timestep in a matrix?

5 visualizaciones (últimos 30 días)
Johanna
Johanna el 9 de Abr. de 2014
Comentada: Johanna el 9 de Abr. de 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

Respuestas (1)

Walter Roberson
Walter Roberson el 9 de Abr. de 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;

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by