How to multiply each elements of single matrix one-by-one?
28 ビュー (過去 30 日間)
古いコメントを表示
I have a matrix Xij:
Xij =[
0 1 -2 2 6
-1 0 -3 1 5
2 3 0 4 8
-2 -1 -4 0 4
-6 -5 -8 -4 0];
I need to multiply each elements of this matrix with each elements of this matrix again. For example, I need to multiply X13*X24 or X12*X24. And I need to multiply for all matrix.
I have tried the code below, but it multiplies just X11*X11 (like square):
Xij =[
0 1 -2 2 6
-1 0 -3 1 5
2 3 0 4 8
-2 -1 -4 0 4
-6 -5 -8 -4 0];
for m=1:5
for n=1:5
A(m,n)=Xij(m,n)*Xij(m,n);
end
end
I got unnecessary result like:
A =
0 1 4 4 36
1 0 9 1 25
4 9 0 16 64
4 1 16 0 16
36 25 64 16 0
Could anyone help me, please?
0 件のコメント
採用された回答
James Tursa
2016 年 7 月 18 日
This will multiply every element by every other element:
result = Xij(:) * Xij(:)'; % <-- Simple outer product of all the elements
If you want the resulting elements to be in a specific order, or the size of the result to be in a specific shape, please specify.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!