How to multiply one array to all elements of a vector with a different size?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (1개)
James Tursa
2022년 1월 27일
편집: James Tursa
2022년 1월 27일
You can use implicit expansion with the element-wise multiply operator:
c = a .* reshape(b,1,1,[]);
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!