convert vector of n or any size into a matrix
Show older comments
Please help me to understand, I have a vector with n elements (which I can know with length), I would like to build a matrix with n / x rows and x columns (where x is a number that I have chosen). If n / x is integer ok but while if not, can I find the nearest whole integer and fill the missing electives with zeros? How could I do?
Accepted Answer
More Answers (2)
Walter Roberson
on 20 Mar 2018
0 votes
If you have the signal processing toolbox then you can use buffer()
Christian
on 25 Mar 2018
0 votes
2 Comments
Walter Roberson
on 25 Mar 2018
buffer() will return a matrix in which the columns are from the consecutive elements. buffer() automatically pads the last entry if needed, and buffer() handles overlaps as well for the cases where you need a sliding window.
Christian
on 26 Mar 2018
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!