How to replace every element of a matrix with another column matrix?
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a matrix y=[0,1,4,2,5,1,5,9,8,.........] it contains n numbers from 0 through 9.
I want to replace each element with a column matrix.
for ex- all 0s in y should be replaced with [1;0;0;0;0;0;0;0;0;0]
like wise all 1s should be replaced with [0;1;0;0;0;0;0;0;0;0]
.
going on 9 should be replaced with [0;0;0;0;0;0;0;0;0;1]
Is there any efficient way to do this?
0 个评论
采纳的回答
Image Analyst
2020-9-12
If you don't have the Deep Learning Toolbox, try this:
y=[0,1,4,2,5,1,5,9,8]
output = zeros(9, length(y))
for col = 1 : length(y)
row = y(col) + 1;
output(row, col) = 1;
end
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!