array to matrix

3 次查看(过去 30 天)
som
som 2012-4-23
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,

采纳的回答

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

更多回答(1 个)

Titus Edelhofer
Titus Edelhofer 2012-4-23
Hi Som,
the function you are looking for is named
repmat
Titus
  2 个评论
Andrei Bobrov
Andrei Bobrov 2012-4-23
and 'reshape'
Titus Edelhofer
Titus Edelhofer 2012-4-23
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by