Can you help me solving that?

2 views (last 30 days)
Rengin
Rengin on 30 Jan 2014
Edited: Walter Roberson on 30 Jan 2014
A=[1 2 3 4 5 6 7 8 9 10]
B=[a b c d e f ]
I want to create such a matrix as a result:
C[1+a 1+b 1+c 1+d 1+e 1+f ; 2+a ... 2+f ; 3+a... 3+f; ......;10+a...10+f]
A is 1x10 and B is 1x6 sized matrices. C is 10x6 sized matrix.
Thank you for your help!

Accepted Answer

Mischa Kim
Mischa Kim on 30 Jan 2014
How about:
A = [1 2 3 4 5 6];
b = [1 2 3];
C = zeros(size(A'*b));
for ii = 1:length(A)
C(ii,:) = b + A(ii);
end

More Answers (2)

Iain
Iain on 30 Jan 2014
Edited: Iain on 30 Jan 2014
C = A * B'; % will give you a 1x1.
C = (A' * B)'; will give you a 10x6.
C = A'*B; will give you a 6 x 10.
  2 Comments
Rengin
Rengin on 30 Jan 2014
Yes you are right but the thing is that I am getting the first element of A matrix (which is "1" ) and adding it the first row of the B matrix and getting the first row of C matrix (1+a 1+b 1+c 1+d 1+e 1+f). I am doing that procedure untill fulfill all of my rows (I have 6 rows)... I know how to multiply the matrices. My guestion is how to create a new matrix according to my specific summary rule.
Jos (10584)
Jos (10584) on 30 Jan 2014
you mean: I have 10 rows ...

Sign in to comment.


Jos (10584)
Jos (10584) on 30 Jan 2014
No need for an explicit loop as you can exploit the power of MatLab with BSXFUN.
% example data
A =[1 2 3 4 5 6 7 8 9 10]
B =[100 200 300 400 500]
% engine
C = bsxfun(@plus, A(:), B)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!