Matrix combining with array in a specific manner
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Andrei Bobrov
2012-6-7
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 个评论
Andrei Bobrov
2012-6-7
Choose other directory for the 'Result.xls' (non 'C:\Program Files\MATLAB\R2012a\bin\')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!