How to store data in regular interval?

6 visualizaciones (últimos 30 días)
Rubel Ahmed
Rubel Ahmed el 8 de Feb. de 2021
Comentada: Rubel Ahmed el 8 de Feb. de 2021
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]

Respuesta aceptada

Walter Roberson
Walter Roberson el 8 de Feb. de 2021
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.

Más respuestas (0)

Categorías

Más información sobre Numeric Types en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by