array to matrix

4 Ansichten (letzte 30 Tage)
som
som am 23 Apr. 2012
Hi all,
I have an array like a:
a=[10 20 30 40];
I want to convert it to the matrix below, without using any for loop just by one command.
b=[ 10 10 20 20 30 30 40 40
10 10 20 20 30 30 40 40
10 10 20 20 30 30 40 40];
How can I do it. Thank you,

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 23 Apr. 2012
a = [10 20 30 40];
b = kron(a,ones(3,2))

Weitere Antworten (1)

Titus Edelhofer
Titus Edelhofer am 23 Apr. 2012
Hi Som,
the function you are looking for is named
repmat
Titus
  2 Kommentare
Andrei Bobrov
Andrei Bobrov am 23 Apr. 2012
and 'reshape'
Titus Edelhofer
Titus Edelhofer am 23 Apr. 2012
Hi Andrei, thanks! I admit I did not see the repetitions in the rows, so my solution would be repmat + reshape. Using kron is in this case the more elegant solution.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by