matrix column multiplication with rows of another matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
this is my (9*9) matrix.
1 1 1 1 0 1 1 1 1
1 1 1 1 1 0 1 1 1
1 1 1 1 1 1 0 1 1
1 1 1 1 1 1 1 0 1
1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1
1 0 1 1 1 1 1 1 1
1 1 0 1 1 1 1 1 1
1 1 1 0 1 1 1 1 1
I would like to multiply entire column 2, 3, and 4 etc. of this matrix with rows of the below column vector matrix one by one.
000
001
010
011
100
101
110
111
This is multiply 000 with column 2 , 3 and 4. which will result entire column 2, 3 and 4 as zero.
Then multiply 001 with column 2 , 3 and 4. which will result entire column 2, 3 as zero and column 4 will remain same. This process should continue for each row.
댓글 수: 5
Image Analyst
2016년 5월 2일
The so-called 15*15 matrix is actually 9*9. Are the 000, etc. supposed to be binary numbers, or decimal?
채택된 답변
Image Analyst
2016년 5월 2일
Try this:
m=[...
1 1 1 1 0 1 1 1 1
1 1 1 1 1 0 1 1 1
1 1 1 1 1 1 0 1 1
1 1 1 1 1 1 1 0 1
1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1
1 0 1 1 1 1 1 1 1
1 1 0 1 1 1 1 1 1
1 1 1 0 1 1 1 1 1]
v = [...
000
001
010
011
100
101
110
111
111]
vm = repmat(v, [1, size(m, 2)])
out = m .* repmat(v, [1, size(m, 2)])
Use bin2dec if your v is actually binary numbers.
댓글 수: 0
추가 답변 (1개)
Roger Stafford
2016년 5월 2일
Let M be your 15 x 15 matrix and A be your n x 3 matrix.
B = zeros(size(M,1),3,size(A,1)); % A three-dimensional result
for k = 1:size(A,1)
B(:,:,k) = bsxfun(@times,A(k,:),M(:,2:4));
end
You have asked that a size(M,1) x 3 result be obtained for each row of A, which has forced me to give you a three-dimensional result.
댓글 수: 1
Roger Stafford
2016년 5월 3일
Monika, you stated “This is multiply 000 with column 2 , 3 and 4. which will result entire column 2, 3 and 4 as zero.” This means, if I understand you correctly, that you first want the entire nine-element columns 2, 3, and 4 to be made into zeros by multiplication with [0 0 0]. That is a 9 by 3 group of zeros. Then you want the same repeated for each row of your eight rows in your second matrix. I conclude that there should be eight times nine times three results and that is why I produced a three dimensional array as the result. The question is why you have now expressed a preference for a different answer with just nine times three elements.
참고 항목
카테고리
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!