MATLAB: Easy beginner question : how to sum up

beginner question sum upmultiply

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

Best Answer

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.)
Related Question