How to store data in regular interval?

7 次查看(过去 30 天)
Hi all,
I am repeating a Array calculation ARPP from time loop for time loops ttt = 1:1:100;
In the time loops, I am calculating a variable ARPP which is a n row and 2 column Array i.e. ARPP(n,2); I want to store the first column of ARPP in PX_store and second column of ARPP in PY_store after every 5 time loops . I am doing this
if mod(ttt,5)==0
PX_store(:,1)= ARPP(:,1);
PY_store(:,1)= ARPP(:,2);
end
But after every 5 time loops, each time the calculated values are replacing in the first column of PX_store, PY_store. But I want to see like this
PX_store = [ARPP 1st column value after 5 loops;ARPP 1st column value after 10 loops;ARPP 1st column value after 15 loops;......ARPP 1st column value after 100 loops]
PY_store = [ARPP 2st column value after 5 loops;ARPP 2st column value after 10 loops;ARPP 2st column value after 15 loops;......ARPP 2st column value after 100 loops]

采纳的回答

Walter Roberson
Walter Roberson 2021-2-8
Initialize:
PX_store = [];
PY_store = [];
Then in the loop:
if mod(ttt,5)==0
PX_store = [PX_store; ARPP(:,1)];
PY_store = [PY_store; ARPP(:,2)];
end
This does not assume that ARPP will be the same size every iteration, and does not assume a maximum number of iterations.
If the code is know to produce the same size each iteration, and the maximum number of iterations is known, then the code can be made more efficient.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by