How can I multiply a row vector with each of two column vectors?

1 view (last 30 days)
I have a row vector and two column vectors, and intend to perform their multiplication (element by element). The following is an example.
t = [1 2];
s = [(1:3)',(4:6)'];
The expected result:
1 4 2 8
2 5 4 10
3 6 6 12

Accepted Answer

Voss
Voss on 18 Feb 2024
One way:
t = [1 2];
s = [(1:3)',(4:6)'];
reshape(t.*s(:),size(s,1),[])
ans = 3×4
1 4 2 8 2 5 4 10 3 6 6 12

More Answers (1)

Torsten
Torsten on 18 Feb 2024
Moved: Torsten on 18 Feb 2024
t = [1 2];
s = [(1:3)',(4:6)'];
kron(t,s)
ans = 3x4
1 4 2 8 2 5 4 10 3 6 6 12

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!