Create the matrix with some limits

How should I do if I want to build a matrix like [1 2 1 2 ......](which length is 10) with two instructions.And one of the instructions is n=10.
I do'nt know how to do it without 'if' and 'for'.

 采纳的回答

Andrei Bobrov
Andrei Bobrov 2019-2-27
kron(ones(1,10),1:2)

更多回答(1 个)

p = [1 2] ;
n = 10 ;
q = repmat(p,1,n)

1 个评论

I think this is the three-instructions solution.If l'm wrong ,please tell me. Thank you.

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by