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

 Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 27 Fév 2019

0 votes

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

1 commentaire

Lee hsuan
Lee hsuan le 27 Fév 2019
Thank you. I forgot this function.Love you dude.

Connectez-vous pour commenter.

Plus de réponses (1)

KSSV
KSSV le 27 Fév 2019
p = [1 2] ;
n = 10 ;
q = repmat(p,1,n)

1 commentaire

Lee hsuan
Lee hsuan le 27 Fév 2019
I think this is the three-instructions solution.If l'm wrong ,please tell me. Thank you.

Connectez-vous pour commenter.

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by