Can I make the matrix of size n with only x elements known and rest all 0?
显示 更早的评论
I have a matrix that can have some x known values. But I want to make it of fixed length n. In other words, I want to append 0s and make one n sized matrix from x known elements and n-x 0s.
I think that this can be surely done by just one for loop, but it would be great if there is a way to do this with a one-line command.
采纳的回答
更多回答(1 个)
Setsuna Yuuki.
2020-11-14
x = [1 2 3 4]
large = 8
x = [x zeros(1,large-length(x))]
类别
在 帮助中心 和 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!