Can you help me solving that?

조회 수: 3 (최근 30일)
Rengin
Rengin 2014년 1월 30일
편집: Walter Roberson 2014년 1월 30일
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!

채택된 답변

Mischa Kim
Mischa Kim 2014년 1월 30일
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
  댓글 수: 1
Rengin
Rengin 2014년 1월 30일
Thank you so much :)

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

추가 답변 (2개)

Iain
Iain 2014년 1월 30일
편집: Iain 2014년 1월 30일
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
Rengin
Rengin 2014년 1월 30일
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) 2014년 1월 30일
you mean: I have 10 rows ...

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


Jos (10584)
Jos (10584) 2014년 1월 30일
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)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by