MATLAB: How to fill matrix in a specific way

MATLAB

Hi I have a matrix like this,
I want to take unique values from column 1 and 2 and sort them. Then create another matrix with rows and columns of sorted matrix and fill it with values in 3rd column of original matrix. like shown in attached image:
Thanks in advance

Best Answer

A = [11 44 1; 11 33 -1; 22 11 1; 22 44 1; 22 33 1;33 44 1; 33 22 -1; 44 11 1 ;
44 22 -1; 44 33 1] ;
c1 = A(:,1) ; c2 = A(:,2) ;
c1 = unique(c1) ;
c2 = unique(c2) ;
iwant = zeros(length(c1)+1,length(c2)+1) ;
iwant(2:end,1) = c1 ;
iwant(1,2:end) = c2 ;
for i = 2:size(iwant,1)
for j = 2:size(iwant,2)
[val,idx] = ismember([iwant(1,i) iwant(j,1)],A(:,1:2),'rows') ;
if idx~=0
iwant(i,j) = A(idx,3) ;
end
end
end