How to create an array with repeating values of a vector

86 次查看(过去 30 天)
how can I create a matrix based on the vector v = [12.56, 65.23, 5.67], which is repeated 20 times? So that the matrix M look like:
M = [12.56 65.23 5.67 ; 12.56 65.23 5.67 ; 12.56 65.23 5.67; .... ; 12.56 65.23 5.67] ?
Thanks a lot.
Harry

采纳的回答

Stephen23
Stephen23 2020-4-7
编辑:Stephen23 2020-4-7
m = repmat(v,20,1)
or
m = v(ones(1,20),:)
or
m = ones(20,1)*v
or
m = zeros(20,1)+v % requires >=R2016b
or
[~,X] = ndgrid(1:20,1:3);
m = v(X)
or ...

更多回答(0 个)

类别

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

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by