Updating with for-loop (straightforward)

9 vues (au cours des 30 derniers jours)
Fiona Rae
Fiona Rae le 10 Juil 2017
Commenté : Fiona Rae le 10 Juil 2017
AA =
2 8 4.........
4 9 34.........
BB =
4 5 2.........
9 23 11.........
dt = 0.1 % time step
for t = 0:dt:4
pA = AA(:, t+1)
pB = BB(:, t+1)
end
There are several other columns for AA and BB. At t = 0, I need to assign the first columns of AA and BB to pA and pB respectively. At t = 0.1, the second columns. At t = 0.2, the third columns and so on.
I know the error is in AA(:, t+1) and BB(:, t+1) because t is in decimals and column numbers cannot be in decimals. I just don't know how to rectify it.

Réponse acceptée

David Goodmanson
David Goodmanson le 10 Juil 2017
Modifié(e) : David Goodmanson le 10 Juil 2017
Hello Fiona,
One way is to use an index to address AA and BB and to calculate t. You have 41 possible values for t, so
for n = 1:41
pA = AA(:,n)
pB = BB(:,n)
t = .1*(n-1); % relationship between n and t
(possibly more calculations involving t inside the loop are here)
end
pA and pB change every time in the loop and are not being saved, so I assume you are doing some calculation with them inside the loop.
  1 commentaire
Fiona Rae
Fiona Rae le 10 Juil 2017
Thank you so much, David!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by