Multiplication between two matrices with different number of rows

1 Ansicht (letzte 30 Tage)
DV
DV am 11 Jul. 2022
Kommentiert: DV am 11 Jul. 2022
Dear all,
I have two matrices:
A=[42x5];
B=[32x1];
I want to multiply each row of B to each of A.
Kind help needed. Thank you.
  2 Kommentare
Stephen23
Stephen23 am 11 Jul. 2022
@DV: please show us the size of the expected output array.
DV
DV am 11 Jul. 2022
Expected to be: C=[42x32x5];
Thanks!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 11 Jul. 2022
Bearbeitet: Stephen23 am 11 Jul. 2022
C = permute(A,[1,3,2]) .* reshape(B,1,[])
  2 Kommentare
Stephen23
Stephen23 am 11 Jul. 2022
Testing:
A = rand(42,5);
B = rand(32,1);
C = permute(A,[1,3,2]) .* reshape(B,1,[]);
size(C)
ans = 1×3
42 32 5

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by