MATLAB Answers

How to sum each column element of one matrix with all column elements of another matrix?

7 ビュー (過去 30 日間)
Sorry I cannot formulate my question in a clearer way. Here is what I want to do: A = [ a, b; c, d ] and B = [ i, j; k, l ] I want to get: C = [ (a+i), (b+j); (a+k), (b+l); (c+i), (d+j); (c+k), (d+l) ]. Thank you in advance.

  0 件のコメント

Sign in to comment.

採用された回答

Anton Semechko
Anton Semechko 2018 年 7 月 8 日
Do
kron([a b;c d],[1;1]) + kron([1;1],[i j;k l])
Here is an example using symbolic expressions
syms a b c d i j k l
kron([a b;c d],[1;1]) + kron([1;1],[i j;k l])
ans =
[ a + i, b + j]
[ a + k, b + l]
[ c + i, d + j]
[ c + k, d + l]

  5 件のコメント

表示 2 件の古いコメント
Jakov Simjanoski
Jakov Simjanoski 2018 年 7 月 8 日
Hello again Anton, sorry, I realized that it works with 2x2 matrices but I need it for n x n matrix (450x450 in particular). Can you help me?
Anton Semechko
Anton Semechko 2018 年 7 月 8 日
Suppose A and B are your two matrices (where A and B are the equivalents of [a b; c d] and [i j;k l], respectively). Do:
N=size(A,1);
C=kron(A,ones(N,1)) + kron(ones(N,1),B);

Sign in to comment.

その他の回答 (0 件)


Translated by