How can I divide each element of a vector by each of the elements of another vector in MATLAB?

21 次查看(过去 30 天)
Say I have two vectors:
a= [ 1
2
3 ];
b=[4
5
6];
And I want
c= [1/4
2/4
3/4
1/5
2/5
3/5
1/6
2/6
3/6];
Is there a way to do this?

采纳的回答

James Tursa
James Tursa 2021-4-8
编辑:James Tursa 2021-4-8
Assuming a and b are both column vectors, you can use automatic array expansion by transposing one of them and using element-wise divide:
c = a ./ b.'; % results in a 2D matrix
c = c(:); % turn 2D matrix into a column vector

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by