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일

2 개 추천

a = [10 20 30 40];
b = kron(a,ones(3,2))

추가 답변 (1개)

Titus Edelhofer
Titus Edelhofer 2012년 4월 23일

0 개 추천

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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

som
2012년 4월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by