matrix column multiplication with rows of another matrix

5 次查看(过去 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
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
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.

更多回答(1 个)

Roger Stafford
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
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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by