フィルターのクリア

issue in matrix multiplication

1 回表示 (過去 30 日間)
mary
mary 2013 年 12 月 4 日
回答済み: Walter Roberson 2013 年 12 月 5 日
G=[1 1 1 1 1 0 0 0 1 0 0 0; 0 0 1 1 0 0 0 1 0 1 0 0; 1 1 1 0 1 0 0 1 0 0 1 0; 1 0 0 1 1 1 0 1 0 0 0 1];
m=[1 0 1 0]
how to multiply them??

採用された回答

Youssef  Khmou
Youssef Khmou 2013 年 12 月 4 日
編集済み: Youssef Khmou 2013 年 12 月 4 日
G is 4x12 and m is 1x4, then two possibilities :
m*G
G'*m'
You do not get binary result because of the multiplication cij=sum a_ik b_kj there is an addition. you can get binary results if the matrices have the same dimensions and you use Hadamard product :
m=m'
M=zeros(4,12);
for n=1:12
M(:,n)=m;
end
M.*G

その他の回答 (4 件)

Wayne King
Wayne King 2013 年 12 月 4 日
編集済み: Wayne King 2013 年 12 月 4 日
G=[1 1 1 1 1 0 0 0 1 0 0 0; 0 0 1 1 0 0 0 1 0 1 0 0; 1 1 1 0 1 0 0 1 0 0 1 0; 1 0 0 1 1 1 0 1 0 0 0 1];
m=[1 0 1 0];
out = m*G;
How else would you presume to multiply them?
  1 件のコメント
mary
mary 2013 年 12 月 4 日
when i multiplied them using this way the result will be [ 2 2 3 2 2 0 0 2 1 1 1 0]

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


Walter Roberson
Walter Roberson 2013 年 12 月 4 日
G is 12 x 4, and m is 1 x 4, so there is no direct way to multiply them. You can, however, use
G * m.'
to get 12 x 1, or you can use
m * G.'
to get 1 x 12
Possibly what you want is
G .* repmat(m.', 1, size(G,2))
  1 件のコメント
mary
mary 2013 年 12 月 4 日
G is 4 by 12 if i multiply them directly the result is not binary ?? how come??

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


sixwwwwww
sixwwwwww 2013 年 12 月 4 日
mary you can get desired output as follows:
G = [1 1 1 1 1 0 0 0 1 0 0 0; 0 0 1 1 0 0 0 1 0 1 0 0; 1 1 1 0 1 0 0 1 0 0 1 0; 1 0 0 1 1 1 0 1 0 0 0 1]';
m = [1 0 1 0];
idx = find(m);
result = zeros(1, size(G, 1));
for i = 1:size(G, 1)
result(i) = sum(G(i, min(idx):max(idx)));
end
disp(result)
Do you need this?
  1 件のコメント
mary
mary 2013 年 12 月 4 日
not this i need the result in binary .. just multiplying two matrices and the result would be binary

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


Walter Roberson
Walter Roberson 2013 年 12 月 5 日

カテゴリ

Help Center および File ExchangeAssembly についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by