Azzera filtri
Azzera filtri

Can you help me solving that?

1 visualizzazione (ultimi 30 giorni)
Rengin
Rengin il 30 Gen 2014
Modificato: Walter Roberson il 30 Gen 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!

Risposta accettata

Mischa Kim
Mischa Kim il 30 Gen 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

Più risposte (2)

Iain
Iain il 30 Gen 2014
Modificato: Iain il 30 Gen 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 Commenti
Rengin
Rengin il 30 Gen 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) il 30 Gen 2014
you mean: I have 10 rows ...

Accedi per commentare.


Jos (10584)
Jos (10584) il 30 Gen 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)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by