how to fill matrix in a specific way

3 Ansichten (letzte 30 Tage)
lucksBi
lucksBi am 16 Mär. 2017
Kommentiert: lucksBi am 16 Mär. 2017
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

Akzeptierte Antwort

KSSV
KSSV am 16 Mär. 2017
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

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by