Can you help me solving that?

2 vues (au cours des 30 derniers jours)
Rengin
Rengin le 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!
  1 commentaire
Image Analyst
Image Analyst le 30 Jan 2014
Is this homework?

Connectez-vous pour commenter.

Réponse acceptée

Mischa Kim
Mischa Kim le 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
  1 commentaire
Rengin
Rengin le 30 Jan 2014
Thank you so much :)

Connectez-vous pour commenter.

Plus de réponses (2)

Iain
Iain le 30 Jan 2014
Modifié(e) : Iain le 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 commentaires
Rengin
Rengin le 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) le 30 Jan 2014
you mean: I have 10 rows ...

Connectez-vous pour commenter.


Jos (10584)
Jos (10584) le 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)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by