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!