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'.

 Accepted Answer

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

1 Comment

Thank you. I forgot this function.Love you dude.

Sign in to comment.

More Answers (1)

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

1 Comment

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

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!