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

 Risposta accettata

Andrei Bobrov
Andrei Bobrov il 27 Feb 2019

0 voti

kron(ones(1,10),1:2)

Più risposte (1)

KSSV
KSSV il 27 Feb 2019
p = [1 2] ;
n = 10 ;
q = repmat(p,1,n)

1 Commento

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

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by