Matrices
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to perform a Principal Component Analysis (PCA) and it is need that matrix has the same number of rows and columns. However, I got a matrix (1142x2) being that first column is composed by number of molecules and second column, species from plants. So, sometimes I got more than one molecule for each plant . In that way, I need to put all species in the rows (173) and the molecules in the columns (712) and put a value (1) only in the correct position, e.g. The 5 speciehave the substances 171, 300, 530, 700, So I need to put the value 1 in (5, 171), (5,300), (5, 530), so on... In the end, I want to construct a matrix of (173x712) which it possesses only values where there is a substance Someone help me Thanks
0 Kommentare
Akzeptierte Antwort
Rick Rosson
am 30 Dez. 2011
Please try the following:
X = [ 5 171 ; 5 300 ; 5 530 ; 5 700 ];
M = 173;
N = 712;
Y = zeros(M,N);
idx = M*(X(:,2)-1) + X(:,1) ;
Y(idx) = 1;
sum(Y(:))
HTH.
Rick
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dimensionality Reduction and Feature Extraction finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!