maximizing efficiency in simple commands

I have an array given by
x = [1 2 3 4];
I would like to create a matrix that looks like
M = [1 2 3 4;
1 2 3 4;
1 2 3 4;
1 2 3 4];
What's the most computationally efficient way to create M from x?

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 20일
편집: Azzi Abdelmalek 2013년 8월 20일

0 개 추천

x=[1 2 3 4];
M=repmat(x,4,1)

댓글 수: 1

Equivalently but removing the error checking:
x=[1 2 3 4];
M = x([1 1 1 1],:);

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

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2013년 8월 20일
편집: Andrei Bobrov 2013년 8월 20일

0 개 추천

ones(4,1)*x
kron(ones(4,1),x)

카테고리

도움말 센터File Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by