How to map a value of a vector into column number of a matrix?
1 次查看(过去 30 天)
显示 更早的评论
let A=[2;4;5] vector I want a matrix where all the values will be zero and the 2nd 4th and 5th element of column of 10x3 matrix will be 1.
B=[0 0 0
1 0 0
0 0 0
0 1 0
0 0 1
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0 ]
0 个评论
采纳的回答
更多回答(2 个)
Jos (10584)
2018-2-1
A fast and easy one-liner from the old days, when accumarray did not exist :)
A = [2 ; 4 ; 5]
B = full(sparse(A, 1:numel(A), 1, 10, 3))
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!