Preallocating and filling long array with shorter arrays
7 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!