How to refer to a previous timestep in a matrix?

5 次查看(过去 30 天)
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

回答(1 个)

Walter Roberson
Walter Roberson 2014-4-9
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;

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by