How to write array results of variable length to zeros matrix matrix?
Show older comments
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!
4 Comments
"The reason I need to put the arrays in a matrix is because I need to sum all of the columns"
The sum of each column would be the same. Why not just do this? (r2016b or later)
sum(vector).*[1,1,1,1]
Also, the first value of the column vector is 0 but I don't see that value represented in the example output. Instead, the last non-zero value of the vector changes in the example output.
tyuky
on 23 Apr 2020
tyuky
on 23 Apr 2020
Adam Danz
on 23 Apr 2020
My answer should solve the problem. If not, please elaborate.
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!