expanding the existing matrix

조회 수: 3 (최근 30일)
mahesh chathuranga
mahesh chathuranga 2013년 9월 12일
I have a matrix like this.
M=[1 2 3;
4 5 6].
I want to expanding it into
M'=[1 1 2 2 3 3;
1 1 2 2 3 3;
1 1 2 2 3 3;
4 4 5 5 6 6;
4 4 5 5 6 6;
4 4 5 5 6 6].
I try to do this.but stil i could not get correct result?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 9월 12일
편집: Andrei Bobrov 2013년 9월 12일
kron(M,ones(3,2))
or
m = 3;
n= 2;
s = size(M);
out = reshape(permute(reshape(repmat(M,m,n),s(1),m,s(2),n),[2 1 4 3]),m*s(1),[]);

추가 답변 (1개)

Matt J
Matt J 2013년 9월 12일
Instead of expanding it (resulting in more memory consumption) consider using this instead

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by