필터 지우기
필터 지우기

Multiply parts of matrices

조회 수: 1 (최근 30일)
Tiffany
Tiffany 2011년 11월 30일
Hello everyone - many thanks for taking the time to read this.
Matrix A is 63x63 and Matrix B is 63x7
I want to multiply every 9x9 of Matrix A with every 9x1 of Matrix B.
So the first:
9x9 in matrix A with the first 9x1 in Matrix B
1 2 3 4 5 6 7 8 9 1
1 2 3 4 5 6 7 8 9 2
1 2 3 4 5 6 7 8 9 3
1 2 3 4 5 6 7 8 9 4
1 2 3 4 5 6 7 8 9 5
1 2 3 4 5 6 7 8 9 6
1 2 3 4 5 6 7 8 9 7
1 2 3 4 5 6 7 8 9 8
1 2 3 4 5 6 7 8 9 9
Then the second 9x9 to the right in matrix A with the second 9x1 in matrix B.
I'm currently doing it using cells which is great but need to be able to do it outside of cell format.
What would you recommend?
  댓글 수: 2
Sean de Wolski
Sean de Wolski 2011년 12월 1일
What's wrong with using cells?
Tiffany
Tiffany 2011년 12월 1일
Absolutely nothing but this has to go in part of a loop where using cells has proved to be very difficult.

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 12월 1일
variant 1
A = randi(100,8,6);
B = randi(50,4,3);
[m n] = size(A);
q = 4;
p = 2;
a1 = reshape(permute(reshape(A,q,m/q,p,[]),[1 3 2 4]),q,p,[]);
out = reshape(sum(bsxfun(@times,a1,reshape(B,1,p,[])),2),m,[]);

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 11월 30일
When you say multiply the 9x9 by the 9x1, is that a matrix multiplication (which would output a 9x1), or is that an element-by-element multiplication producing 9 x 9 with each row in A multiplied the (single) value from the corresponding column in B ?
  댓글 수: 4
Tiffany
Tiffany 2011년 12월 1일
Brill, I'll check that out. Thanks!
Walter Roberson
Walter Roberson 2011년 12월 1일
Correction:
Bcol = 1 + (block_struct.location(2) - 1)/9

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by