How to create an array with repeating values of a vector

조회 수: 105 (최근 30일)
Harald von der Osten
Harald von der Osten 2020년 4월 7일
댓글: Harald von der Osten 2020년 4월 7일
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