Updating with for-loop (straightforward)
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Fiona Rae
am 10 Jul. 2017
Kommentiert: Fiona Rae
am 10 Jul. 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.
0 Kommentare
Akzeptierte Antwort
David Goodmanson
am 10 Jul. 2017
Bearbeitet: David Goodmanson
am 10 Jul. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!