Updating with for-loop (straightforward)
9 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
David Goodmanson
on 10 Jul 2017
Edited: David Goodmanson
on 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.
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!