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

2 次查看(过去 30 天)
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

采纳的回答

Voss
Voss 2024-2-18
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

更多回答(1 个)

Torsten
Torsten 2024-2-18
移动:Torsten 2024-2-18
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

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by