How to store data in regular interval?
조회 수: 5 (최근 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]
댓글 수: 0
채택된 답변
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 Exchange에서 Numeric Types에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!