How to store data in regular interval?

2 ビュー (過去 30 日間)
Rubel Ahmed
Rubel Ahmed 2021 年 2 月 8 日
コメント済み: Rubel Ahmed 2021 年 2 月 8 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by