Effacer les filtres
Effacer les filtres

How to store data in regular interval?

2 vues (au cours des 30 derniers jours)
Rubel Ahmed
Rubel Ahmed le 8 Fév 2021
Commenté : Rubel Ahmed le 8 Fév 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]

Réponse acceptée

Walter Roberson
Walter Roberson le 8 Fév 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.

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