matrix column multiplication with rows of another matrix

1 Ansicht (letzte 30 Tage)
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 Kommentare
Monika  Kok
Monika Kok am 2 Mai 2016
yeah that is (9*9) matrix... sorry for the wrong typing.
Image Analyst
Image Analyst am 2 Mai 2016
The so-called 15*15 matrix is actually 9*9. Are the 000, etc. supposed to be binary numbers, or decimal?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 2 Mai 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.

Weitere Antworten (1)

Roger Stafford
Roger Stafford am 2 Mai 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 Kommentar
Roger Stafford
Roger Stafford am 3 Mai 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by