matrix column multiplication with rows of another matrix

1 visualización (últimos 30 días)
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 comentarios
Monika  Kok
Monika Kok el 2 de Mayo de 2016
yeah that is (9*9) matrix... sorry for the wrong typing.
Image Analyst
Image Analyst el 2 de Mayo de 2016
The so-called 15*15 matrix is actually 9*9. Are the 000, etc. supposed to be binary numbers, or decimal?

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 2 de Mayo de 2016
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.

Más respuestas (1)

Roger Stafford
Roger Stafford el 2 de Mayo de 2016
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 comentario
Roger Stafford
Roger Stafford el 3 de Mayo de 2016
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by