multiple matrix manipulation with different size matrices

4 ビュー (過去 30 日間)
Jennifer
Jennifer 2011 年 4 月 19 日
Hello
I have two matrices (A and B) and am trying to combine them so that I can have the final matrix C. A small example of what I'm after is below.
A = 1 1
1 1
B = 4 3 2 6
7 8 2 1
3 2 4 5
1 4 3 2
Hence C = A(1,1)*sum[B(1,1),B(1,2),B(2,1),B(2,2)] etc
giving C = 22 11
10 14
I figure that I am going to require a loop in order to do this but I am unsure on how to proceed.
Please note that the actual matrices I have to perform this task on will be (100*100) size. I have scaled the problem down for this example.
Any help would be greatly appreciated.
Thanks
  2 件のコメント
Oleg Komarov
Oleg Komarov 2011 年 4 月 19 日
Do you have the Image Processiong TB?
Jennifer
Jennifer 2011 年 4 月 19 日
Not that I am aware of.

サインインしてコメントする。

採用された回答

Matt Fig
Matt Fig 2011 年 4 月 19 日
It looks like you are basically doing a 2D convolution:
C2 = conv2(B,A,'valid'); % Look at the corners...

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2011 年 4 月 19 日
variant
[m1 n1] = size(B);
[m2 n2] = size(A);
Y = reshape(B,m1,n2,[]);
Y1 = permute(Y,[2 1 3]);
Y2 = reshape(Y1,m1,[]);
C = reshape(sum(Y2).*A(:).',m2,[]);

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by