For neural networking, I would like to represent a column vector y = [1;2;3] in a matrix like so:
y = [1 0 0; 0 1 0; 0 0 1] My vector y is very large, and so hardcoding is not an option. Also, I would like to avoid using for-loops.
What I did so far:
y1 =[y; zeros(1,length(y)) ;zeros(1,length(y))] % add two rows with zeros in orde to give y the right format idx = find(y1(1,:) == 2); % find all the columns containing a 2 y1(:,idx(1):idx(end)) = y1(:,[0;1;0]); % this does not work because now I am comparing a matrix with a vector I also tried this:
y1( y1 == [2;0;0] )=[0;1;0]; % This of course does not work Is there a way to specify I want to compare columns in y1 == [2;0;0], or is there another way to solve this?