MATLAB: How to write array results of variable length to zeros matrix matrix

arrayarray storageMATLABunit hydrograph

Hi!
I'm trying to find the most efficient way to write arrays to a zeros matrix. I have another function that creates the array, now I'm just trying to figure out the most efficient way to store it in a matrix. I also need to lag the arrays by 1 column and 1 row for subsequent arrays as well. For those of you who are familiar with Unit Hydrograph convolution, that's what I'm doing. The reason I need this to be as fast as possible is because I'm going to be running this code for like 20,000 time steps. Also, I should mention I'm a Matlab Noob.
Here's the array I've already calculated:
I want to put it in this zeros matrix:
What I want to output is this:
The reason I need to put the arrays in a matrix is because I need to sum all of the rows across the columns and place into a new array. I should also mention that the arrays might be variable lengths and not all will be the same magnitude, as shown here, during actual implementation of the code depending on the storm event.
Thanks for any help you can provide!

Best Answer

From the example inputs/outputs given in the quesiton, I don't know what's happening to the first 0 at index 1 which doesn't appear in the outputs. I also don't know where the last non-zero value in the output comes from since it differs from the last non-zero value in the input.
Assuming this is an error, here's how to produce that matrix using circshift.
data = [rand(25,1);0;0;0]; % input vector
M = cell2mat(arrayfun(@(i){circshift(data(:),i)},0:3));% output matrix
To get the sum of each row,
sum(M,2)
It also may be useful for you to explore the movsum() function.