How to make new elements (columns) in a vector (matrix) based on the each value of this vector?
1 次查看(过去 30 天)
显示 更早的评论
How to expand each element of a vector with ones based on the value of this element.
For example, if vector is: A=[4 2 3 ...], then the new vector will be: C=[1 1 1 1 1 1 1 1 1 ...]. So, the number of how many ones depend on the value of each element of this vector A.
Thanks, Khalid
0 个评论
采纳的回答
Azzi Abdelmalek
2016-8-14
A=[4 2 3]
C=ones(1,sum(A))
3 个评论
Azzi Abdelmalek
2016-8-14
编辑:Azzi Abdelmalek
2016-8-14
C=[];
for k=1:5
A(k)=randi(10) % Example of generating
C=[C ones(1,A(k))]
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!