Repetition of rows of a matrix maintaining the number of columns

조회 수: 1 (최근 30일)
Iván
Iván 2011년 12월 13일
Hi all.
I also want to create a new matrix from a previous one (A) such all the elements in the first row are copied with N replications and the same should be done for the next row till I reach last row.
The order of new matrix is also N * [rows(A)*cols(A)]; but in my case its number of rows has to be N*rows(A) and the number of columns has to be the same as the previous (A) matrix.
For example, imagine my A matrix is A=[ 1 2
3 4
5 6]
If I replicate N=2 all the rows, my new A_ matrix should be A_=[1 2
1 2
3 4
3 4
5 6
5 6]
Can you help me, please?
Thanks and regards
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2011년 12월 13일
+1 Well written question with sample data, operation, result and proof you searched the records (a rarity)!

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

답변 (1개)

Paulo Silva
Paulo Silva 2011년 12월 13일
A=[ 1 2
3 4
5 6]
N=1; %number of repeats
kron(A,ones(N+1,1))
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2011년 12월 13일
+1`But I'd recommend for readability purpose keeping N to be the number of repeats as a multiplicative number, i.e. 1 repeat = what you have, two repeats = Ivan's example etc.

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by