Preallocating and filling long array with shorter arrays
조회 수: 6 (최근 30일)
이전 댓글 표시
Hello dear community,
I have a question:
If I want to fll an array with single values using preallocation, I do:
input = zeros(1,1000000);
for k = 2:1000000
input(k) = input(k-1) + 5; % 5 is a newdata value in this example
end
so, in input will be stored values 0, 5, 10, 15, 20....
*********************************************************************
now, I have a data input from arrays (ex.) 5 values long, and I want to concatenate them to one big input array after every loop:
newdata:
4 5 7 8 9, 5 8 7 9 5, 1 7 8 9 6, 1 2 3 6 5
to one array input in few steps:
4 5 7 8 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
............
4 5 7 8 9 5 8 7 9 5 1 7 8 9 6 1 2 3 6 5
If I create a big zeroarray, and then create an input variable in a loop, I just create every time a new variable in a loop. How can I use the method from single variable by arrays to use preallocation?
input = [zeros(20,[])]; %it has no sence
for i = 1 : total_frames
input = [input;newdata];
end
Thank you!
P.S. Actually, I'm working with big arrays (48000 * 100000000), the short example is just for better understanding. I want to make my algorithm time efficient.
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!