How to replace every element of a matrix with another column matrix?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Image Analyst
on 12 Sep 2020
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
More Answers (1)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!