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

 Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 27 Feb. 2019

0 Stimmen

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

1 Kommentar

Lee hsuan
Lee hsuan am 27 Feb. 2019
Thank you. I forgot this function.Love you dude.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

KSSV
KSSV am 27 Feb. 2019

0 Stimmen

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

1 Kommentar

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by