Matrix combining with array in a specific manner
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello MATLABERS,
how do i combine a array of integers with a Matrix of Integers. ex: Matrix A = [1 2 3 4 5 6 7 8 9 10] is combined with a matrix B = [2 5 7;1 2 9 ;4 5 6] in such a way that the resultant matrix C results should be as follows: so if a sequence has a one in it, it is stored right under one==>
[1 2 3 4 5 6 7 8 9 10;0 2 0 0 5 0 7 0 0 0;1 2 0 0 0 0 0 0 9 ;0 0 0 4 5 6 0 0 0]
1 2 3 4 5 6 7 8 9 10
0 2 0 0 5 0 7 0 0 0
1 2 0 0 0 0 0 0 9 0
0 0 0 4 5 6 0 0 0
P.s if ur interested in only a scalar combined with a matrix a quick solution was posted by Wayne King http://www.mathworks.com/matlabcentral/answers/40436-matrix-filling
0 Commenti
Risposta accettata
Andrei Bobrov
il 7 Giu 2012
i1 = arrayfun(@(ii)ismember(A,B(ii,:)),(1:size(B,1)),'un',0);
out = ones(size(B,1),1)*A.*cat(1,i1{:});
or
out = bsxfun(@times,cat(1,i1{:}),A)
2 Commenti
Andrei Bobrov
il 7 Giu 2012
Choose other directory for the 'Result.xls' (non 'C:\Program Files\MATLAB\R2012a\bin\')
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!