How to multiply one array to all elements of a vector with a different size?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Take
a=[1 2; 3 4]
and
b=[4 5 6]
How can I creat a 3D vector,
c(:,:,1)=a*b(1)
c(:,:,2)=a*b(2)
c(:,:,3)=a*b(3)
if I don't want to use a for loop. Is there any code for this multiplication in MATLAB?
0 Kommentare
Antworten (1)
James Tursa
am 27 Jan. 2022
Bearbeitet: James Tursa
am 27 Jan. 2022
You can use implicit expansion with the element-wise multiply operator:
c = a .* reshape(b,1,1,[]);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB 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!