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?

采纳的回答

Image Analyst
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 个)

KSSV
KSSV 2020-9-12

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by