MATLAB: Put the result in one matrix

vectors

Hi,I have ,w=[2 4 4 1 1].
for i=1:length(w)
x=find(w==w(i))
end
this code gives this result:x=[1]',x=[2 3]',x=[4 5]',x=[4 5]',in each iteration.
I want the result to be x=1 0 0 0
2 3 0 0
4 5 0 0
4 5 0 0

Best Answer

Actually, your code does not give the result you post when I run it. The second row, [2 3 0 0] is repeated (as it should be) in the third.
I suggest:
w=[2 4 4 1 1];
x = zeros(4,4);
for i=1:length(w)
wi = find(w==w(i))
x(i,1:length(wi))=wi;
end
that produces:
x =
1 0 0 0
2 3 0 0
2 3 0 0
4 5 0 0
4 5 0 0