I think this i quite easy for you guys - but ive not found an answer yet (perhaps because my english skills are limitated) I want to summ up two vektors like this V1 = [1 2 3] V2 = V1' (the transposed vektor) and I want to get the ?inner? sum
1 2 3
1
2
3
so that i get a matrix with this relsult ( so just row plus column )
2 3 4
3 4 5
4 5 6
would be really nice if you can help me. thx a lot

댓글 수: 2

John D'Errico
John D'Errico 2017년 4월 12일
You called this an inner sum. But really, the correct term would be a generalized outer product.
https://en.wikipedia.org/wiki/Outer_product
James Tursa
James Tursa 2017년 4월 12일
편집: James Tursa 2017년 4월 12일
OP is summing, not multiplying. I.e., an "outer sum" not an "outer product"

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

 채택된 답변

Star Strider
Star Strider 2017년 4월 12일

1 개 추천

Use the bsxfun function with the @plus function:
A = [1 2 3];
B = bsxfun(@plus, A(:), A)
B =
2 3 4
3 4 5
4 5 6
(In R2017a, this implicit expansion is done automatically. I still prefer bsxfun because it will throw an error if I do something wrong.)

댓글 수: 2

Sean de Wolski
Sean de Wolski 2017년 4월 12일
How would bsxfun throw an error that implicit expansion won't?
Star Strider
Star Strider 2017년 4월 12일
I’ve not tried implicit expansion without bsxfun. I’m in no rush to do so.

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

추가 답변 (2개)

Guillaume
Guillaume 2017년 4월 12일

2 개 추천

If you're using R2016b or later, simply
V1 + V1.'
In earlier versions
bsxfun(@plus, V1, V1.')
Paul Hoffmann
Paul Hoffmann 2017년 4월 13일

0 개 추천

thx for the answer - helped a lot !

카테고리

도움말 센터File Exchange에서 Variables에 대해 자세히 알아보기

질문:

2017년 4월 12일

답변:

2017년 4월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by